Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Sorting files by month

Reply
 
Old 3 Weeks Ago   #1 (permalink)
Ed


 
 

Sorting files by month

How would you write a script to sort files by month. For example a file named
January 1, February 13, March 27, etc. I have a folder that has files in it
with a daily log for each day. Each file is called Aug. 1, 09; Aug. 2, 09,
etc., Sept. 1, Oct. 1, 09. How would I sort them by month, day, year. Please
be detail with answer since I am new to scripting. Any where can I get more
info.
--
Ed

My System SpecsSystem Spec
Old 3 Weeks Ago   #2 (permalink)
Paul Randall


 
 

Re: Sorting files by month


"Ed" <Ed@newsgroup> wrote in message
news:0865DB3F-4E20-46B1-9495-1DAEE383CDF3@newsgroup
Quote:

> How would you write a script to sort files by month. For example a file
> named
> January 1, February 13, March 27, etc. I have a folder that has files in
> it
> with a daily log for each day. Each file is called Aug. 1, 09; Aug. 2, 09,
> etc., Sept. 1, Oct. 1, 09. How would I sort them by month, day, year.
> Please
> be detail with answer since I am new to scripting. Any where can I get
> more
> info.
First, you have to be clearer on what you mean. One person might think that
you want them sorted in this order when you look at them (the names of the
files) in a folder explorer window. Another person might think you want
them sorted this way when their names are listed in an Excel table or in a
web page or printed on paper. Someone else might think you want the files
physically moved around on the hard drive to be placed in this order. You
might mean something entirely different.

-Paul Randall


My System SpecsSystem Spec
Old 3 Weeks Ago   #3 (permalink)
James Watkins


 
 

Re: Sorting files by month


"Ed" <Ed@newsgroup> wrote in message
news:0865DB3F-4E20-46B1-9495-1DAEE383CDF3@newsgroup
Quote:

> How would you write a script to sort files by month. For example a file
> named
> January 1, February 13, March 27, etc. I have a folder that has files in
> it
> with a daily log for each day. Each file is called Aug. 1, 09; Aug. 2, 09,
> etc., Sept. 1, Oct. 1, 09. How would I sort them by month, day, year.
> Please
> be detail with answer since I am new to scripting. Any where can I get
> more
> info.
> --
> Ed
After following Paul's suggestions, consider downloading the VB Script help
file script56.chm from
http://www.microsoft.com/downloads/d...displaylang=en
so that you can write at least some of the code yourself rather than holding
out an empty hand and asking someone to do all the work for you. You might
also view the posts in this newsgroup - there are lots of scripting examples
here.


My System SpecsSystem Spec
Old 3 Weeks Ago   #4 (permalink)
Dr J R Stockton


 
 

Re: Sorting files by month

In microsoft.public.scripting.vbscript message <0865DB3F-4E20-46B1-9495-
1DAEE383CDF3@newsgroup>, Sat, 31 Oct 2009 11:10:01, Ed
<Ed@newsgroup> posted:
Quote:

>How would you write a script to sort files by month. For example a file named
>January 1, February 13, March 27, etc. I have a folder that has files in it
>with a daily log for each day. Each file is called Aug. 1, 09; Aug. 2, 09,
>etc., Sept. 1, Oct. 1, 09. How would I sort them by month, day, year. Please
>be detail with answer since I am new to scripting. Any where can I get more
>info.
I would do it mainly by pressing keys.

Such programming tasks are much easier if dates (and times) are all
given in ISO 8601 form ; it is at present 2009-11-01 17:11 GMT.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
My System SpecsSystem Spec
Old 3 Weeks Ago   #5 (permalink)
mayayana


 
 

Re: Sorting files by month

James Watkins provided a link to the scripting help.
Once you have that, see the FileSystemObject (FSO).
With FSO you can access a folder and its files as
objects. Each file has a Name property. Then there's
a Split function that will return an array from a string,
based on delimiters.
Say you have the file Oct. 1, 09 and you return its
name. Then you could do the following to simplify
the operation:

sName = Replace(sName, ",", "") ' remove comma
sName = Replace(sName, ".", "") ' remove period.
AName = Split(sName, " ")

That will split sName into an array by splitting it at
each space. The result will be:

AName(0) = "Oct"
AName(1) = "1"
AName(2) = "09"

Once you have that array it's easy to sort the items:

sMonth = AName(0)
Select Case sMonth
Case "Jan"

Case "Feb"

' ...etc....
End Select

That should be enough info., along with the help
file, to work out the details of the sorting. It's hard
to make it more clear without just writing your
whole script for you.
Quote:

> How would you write a script to sort files by month. For example a file
named
Quote:

> January 1, February 13, March 27, etc. I have a folder that has files in
it
Quote:

> with a daily log for each day. Each file is called Aug. 1, 09; Aug. 2, 09,
> etc., Sept. 1, Oct. 1, 09. How would I sort them by month, day, year.
Please
Quote:

> be detail with answer since I am new to scripting. Any where can I get
more
Quote:

> info.
> --
> Ed

My System SpecsSystem Spec
Old 3 Weeks Ago   #6 (permalink)
Todd Vargo


 
 

Re: Sorting files by month

Ed wrote:
Quote:

> How would you write a script to sort files by month. For example a
> file named January 1, February 13, March 27, etc. I have a folder
> that has files in it with a daily log for each day. Each file is
> called Aug. 1, 09; Aug. 2, 09, etc., Sept. 1, Oct. 1, 09. How would I
> sort them by month, day, year. Please be detail with answer since I
> am new to scripting. Any where can I get more info.
Since the daily logs are presumed to be saved on the respective dates
mentioned, I would just click on "Modified" at the top of the date column in
Explorer to sort them by date. No scripting needed.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 2 Weeks Ago   #7 (permalink)
gimme_this_gimme_that


 
 

Re: Sorting files by month

If you rename the files using YYYYMMDD format the files will sort
themselves.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Sorting files VB Script
zip files created within same month PowerShell
Sorting files in a folder VB Script
Autmatically Sorting Files Vista General
WMP - sorting files Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46