Prev: Simulating a button click to bypass a prompt
Next: connecting to remote registry not working sometimes
From: Ed on 31 Oct 2009 14:10 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
From: Paul Randall on 31 Oct 2009 16:21 "Ed" <Ed(a)discussions.microsoft.com> wrote in message news:0865DB3F-4E20-46B1-9495-1DAEE383CDF3(a)microsoft.com... > 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
From: James Watkins on 31 Oct 2009 17:27 "Ed" <Ed(a)discussions.microsoft.com> wrote in message news:0865DB3F-4E20-46B1-9495-1DAEE383CDF3(a)microsoft.com... > 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/details.aspx?familyid=01592C48-207D-4BE1-8A76-1C4099D7BBB9&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.
From: Dr J R Stockton on 1 Nov 2009 12:11 In microsoft.public.scripting.vbscript message <0865DB3F-4E20-46B1-9495- 1DAEE383CDF3(a)microsoft.com>, Sat, 31 Oct 2009 11:10:01, Ed <Ed(a)discussions.microsoft.com> posted: >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.
From: mayayana on 1 Nov 2009 13:52 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. > 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
|
Next
|
Last
Pages: 1 2 Prev: Simulating a button click to bypass a prompt Next: connecting to remote registry not working sometimes |