Windows Vista Forums

How to Sort on Date in Filename?
  1. #1


    Davy Guest

    How to Sort on Date in Filename?

    I have files whose filenames include date created; with the filename
    format ddmmmfilename2, ddmmmfilename3, etc in a folder.

    In Windows Explorer I want to view the files in date sequence. How can I
    manipulate the ddmmm into a format that can be logically sorted?

    thanks

    Davy



      My System SpecsSystem Spec

  2. #2


    Pegasus [MVP] Guest

    Re: How to Sort on Date in Filename?



    "Davy" <me@newsgroup> said this in news item
    news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup

    > I have files whose filenames include date created; with the filename
    > format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >
    > In Windows Explorer I want to view the files in date sequence. How can I
    > manipulate the ddmmm into a format that can be logically sorted?
    >
    > thanks
    >
    > Davy
    Since you specifically mention Windows Explorer, I think you're posting in
    the wrong group. This group focuses on VB Scripting. A Windows XP (?) or a
    Windows file system newsgroup may be a better place. Anyway, since you named
    your files ddmmmFilename you have three options:
    - Sort by dd (which is probably useless)
    - Sort by file date, by clicking the file date column header in Explorer.
    - Rename the files to yyyymmddFilename (where mm is the month *number*, not
    name).


      My System SpecsSystem Spec

  3. #3


    Davy Guest

    Re: How to Sort on Date in Filename?

    "Pegasus [MVP]" <news@newsgroup> wrote in
    news:#I8TjnKjKHA.4048@newsgroup:

    > "Davy" <me@newsgroup> said this in news item
    > news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup

    >> I have files whose filenames include date created; with the
    filename

    >> format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >>
    >> In Windows Explorer I want to view the files in date sequence. How
    >> can I manipulate the ddmmm into a format that can be logically
    >> sorted?
    >>
    >> thanks
    >>
    >> Davy
    >
    > Since you specifically mention Windows Explorer, I think you're
    > posting in the wrong group. This group focuses on VB Scripting. A
    > Windows XP (?) or a Windows file system newsgroup may be a better
    > place. Anyway, since you named your files ddmmmFilename you have
    three

    > options: - Sort by dd (which is probably useless)
    > - Sort by file date, by clicking the file date column header in
    > Explorer. - Rename the files to yyyymmddFilename (where mm is the
    > month *number*, not name).
    >
    >
    Pegasus, thanks for the prompt reply. I now realise that my post was
    not as clear as I imagined.
    Although I want to use Windows Explorer to view the list of files, I
    want to use VBS to rename the files so that they can be sorted
    meaningfully by date.
    There are too many files to rename manually.
    Unfortunately the files' 'date created' property does not reflect the
    date created; just the date these files were placed into their current
    context.
    I realise that I could write some VBS script along the lines of;
    if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    to mmdd so can be meaningfully sorted.
    But I had hoped that there might be a VBS function that can parse a
    date in the format ddmmm and recognise it and then another function to
    convert it to a format that can be put into a file name for sorting.

    Hope this makes sense, my VBS knowledge is somewhat limited.

    cheers, DAvy

      My System SpecsSystem Spec

  4. #4


    Pegasus [MVP] Guest

    Re: How to Sort on Date in Filename?



    "Davy" <me@newsgroup> said this in news item
    news:Xns9CF6622D5830Fmeremoveallthistextc@newsgroup

    > "Pegasus [MVP]" <news@newsgroup> wrote in
    > news:#I8TjnKjKHA.4048@newsgroup:
    >

    >> "Davy" <me@newsgroup> said this in news item
    >> news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup

    >>> I have files whose filenames include date created; with the
    > filename

    >>> format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >>>
    >>> In Windows Explorer I want to view the files in date sequence. How
    >>> can I manipulate the ddmmm into a format that can be logically
    >>> sorted?
    >>>
    >>> thanks
    >>>
    >>> Davy
    >>
    >> Since you specifically mention Windows Explorer, I think you're
    >> posting in the wrong group. This group focuses on VB Scripting. A
    >> Windows XP (?) or a Windows file system newsgroup may be a better
    >> place. Anyway, since you named your files ddmmmFilename you have
    > three

    >> options: - Sort by dd (which is probably useless)
    >> - Sort by file date, by clicking the file date column header in
    >> Explorer. - Rename the files to yyyymmddFilename (where mm is the
    >> month *number*, not name).
    >>
    >>
    >
    > Pegasus, thanks for the prompt reply. I now realise that my post was
    > not as clear as I imagined.
    > Although I want to use Windows Explorer to view the list of files, I
    > want to use VBS to rename the files so that they can be sorted
    > meaningfully by date.
    > There are too many files to rename manually.
    > Unfortunately the files' 'date created' property does not reflect the
    > date created; just the date these files were placed into their current
    > context.
    > I realise that I could write some VBS script along the lines of;
    > if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    > to mmdd so can be meaningfully sorted.
    > But I had hoped that there might be a VBS function that can parse a
    > date in the format ddmmm and recognise it and then another function to
    > convert it to a format that can be put into a file name for sorting.
    >
    > Hope this makes sense, my VBS knowledge is somewhat limited.
    >
    > cheers, DAvy
    OK, I got misled by your subject line. It seems you wish to "rename" rather
    than to "sort" your files. If you put the words "bulk rename" into a Google
    search box then you will get a large number of hits for renaming tools, many
    of the free. Some might actually do exactly what you want to do.

    If you can't find one then the File System Object has methods to do this.
    The following code fragment illustrates the concept:
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    dDate = oFSO.GetFile("d:\tools\att.vbs").DateLastModified
    WScript.Echo Year(dDate), Month(dDate), Day(dDate)

    You would need to write a script that enumerates every file in the folder
    and renames it with the rename method of the File System Object. Remember to
    pad your days and months with a leading zero if necessary and to deal with
    the case where two files might get the same name.


      My System SpecsSystem Spec

  5. #5


    Davy Guest

    Re: How to Sort on Date in Filename?

    "Pegasus [MVP]" <news@newsgroup> wrote in
    news:OZaEAhSjKHA.5604@newsgroup:

    > "Davy" <me@newsgroup> said this in news item
    > news:Xns9CF6622D5830Fmeremoveallthistextc@newsgroup

    >> "Pegasus [MVP]" <news@newsgroup> wrote in
    >> news:#I8TjnKjKHA.4048@newsgroup:
    >>

    >>> "Davy" <me@newsgroup> said this in news item
    >>> news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup
    >>>> I have files whose filenames include date created; with the
    >> filename

    >>>> format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >>>>
    >>>> In Windows Explorer I want to view the files in date sequence.
    How

    >>>> can I manipulate the ddmmm into a format that can be logically
    >>>> sorted?
    >>>>
    >>>> thanks
    >>>>
    >>>> Davy
    >>>
    >>> Since you specifically mention Windows Explorer, I think you're
    >>> posting in the wrong group. This group focuses on VB Scripting. A
    >>> Windows XP (?) or a Windows file system newsgroup may be a better
    >>> place. Anyway, since you named your files ddmmmFilename you have
    >> three

    >>> options: - Sort by dd (which is probably useless)
    >>> - Sort by file date, by clicking the file date column header in
    >>> Explorer. - Rename the files to yyyymmddFilename (where mm is the
    >>> month *number*, not name).
    >>>
    >>>
    >>
    >> Pegasus, thanks for the prompt reply. I now realise that my post
    was

    >> not as clear as I imagined.
    >> Although I want to use Windows Explorer to view the list of files,
    I

    >> want to use VBS to rename the files so that they can be sorted
    >> meaningfully by date.
    >> There are too many files to rename manually.
    >> Unfortunately the files' 'date created' property does not reflect
    the

    >> date created; just the date these files were placed into their
    >> current context.
    >> I realise that I could write some VBS script along the lines of;
    >> if mmm is 'Dec' then replace with '12', etc, etc. Then reformat
    date

    >> to mmdd so can be meaningfully sorted.
    >> But I had hoped that there might be a VBS function that can parse a
    >> date in the format ddmmm and recognise it and then another function
    >> to convert it to a format that can be put into a file name for
    >> sorting.
    >>
    >> Hope this makes sense, my VBS knowledge is somewhat limited.
    >>
    >> cheers, DAvy
    >
    > OK, I got misled by your subject line. It seems you wish to "rename"
    > rather than to "sort" your files. If you put the words "bulk rename"
    > into a Google search box then you will get a large number of hits
    for

    > renaming tools, many of the free. Some might actually do exactly
    what

    > you want to do.
    >
    > If you can't find one then the File System Object has methods to do
    > this. The following code fragment illustrates the concept:
    > Set oFSO = CreateObject("Scripting.FileSystemObject")
    > dDate = oFSO.GetFile("d:\tools\att.vbs").DateLastModified
    > WScript.Echo Year(dDate), Month(dDate), Day(dDate)
    >
    > You would need to write a script that enumerates every file in the
    > folder and renames it with the rename method of the File System
    > Object. Remember to pad your days and months with a leading zero if
    > necessary and to deal with the case where two files might get the
    same

    > name.
    >
    >
    Pegasus, thanks for the suggestions.
    I have several file-renaming pieces of software - non of which have
    sufficient logic to do what I want.
    Regarding your code fragment; the DateLastModified is useless to me
    since I need the date of original creation of the file; which is
    recorded in the filename in the format ddmmmfilename1 etc.

    So I need to take the ddmmm part of the filename and re-insert it back
    into the file name in the format mmddfilename1 etc. Obviously I can do
    this with some clumsy manipulation along the lines of:
    if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date

    but I was hoping to find out if there was some clever date recognition
    function in VBS

    cheeers

    DAvy

      My System SpecsSystem Spec

  6. #6


    Bob Barrows Guest

    Re: How to Sort on Date in Filename?

    Davy wrote:

    > "Pegasus [MVP]" <news@newsgroup> wrote in
    > news:OZaEAhSjKHA.5604@newsgroup:
    >

    >> "Davy" <me@newsgroup> said this in news item
    >> news:Xns9CF6622D5830Fmeremoveallthistextc@newsgroup

    >>> "Pegasus [MVP]" <news@newsgroup> wrote in
    >>> news:#I8TjnKjKHA.4048@newsgroup:
    >>>
    >>>> "Davy" <me@newsgroup> said this in news item
    >>>> news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup
    >>>>> I have files whose filenames include date created; with the
    >>>>> filename format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >>>>>
    >>>>> In Windows Explorer I want to view the files in date sequence. How
    >>>>> can I manipulate the ddmmm into a format that can be logically
    >>>>> sorted?
    >>>>>
    >>>>> thanks
    >>>>>
    >>>>> Davy
    >>>>
    >>>> Since you specifically mention Windows Explorer, I think you're
    >>>> posting in the wrong group. This group focuses on VB Scripting. A
    >>>> Windows XP (?) or a Windows file system newsgroup may be a better
    >>>> place. Anyway, since you named your files ddmmmFilename you have
    >>>> three options: - Sort by dd (which is probably useless)
    >>>> - Sort by file date, by clicking the file date column header in
    >>>> Explorer. - Rename the files to yyyymmddFilename (where mm is the
    >>>> month *number*, not name).
    >>>>
    >>>>
    >>>
    >>> Pegasus, thanks for the prompt reply. I now realise that my post was
    >>> not as clear as I imagined.
    >>> Although I want to use Windows Explorer to view the list of files, I
    >>> want to use VBS to rename the files so that they can be sorted
    >>> meaningfully by date.
    >>> There are too many files to rename manually.
    >>> Unfortunately the files' 'date created' property does not reflect
    >>> the date created; just the date these files were placed into their
    >>> current context.
    >>> I realise that I could write some VBS script along the lines of;
    >>> if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    >>> to mmdd so can be meaningfully sorted.
    >>> But I had hoped that there might be a VBS function that can parse a
    >>> date in the format ddmmm and recognise it and then another function
    >>> to convert it to a format that can be put into a file name for
    >>> sorting.
    >>>
    >>> Hope this makes sense, my VBS knowledge is somewhat limited.
    >>>
    >>> cheers, DAvy
    >>
    >> OK, I got misled by your subject line. It seems you wish to "rename"
    >> rather than to "sort" your files. If you put the words "bulk rename"
    >> into a Google search box then you will get a large number of hits for
    >> renaming tools, many of the free. Some might actually do exactly what
    >> you want to do.
    >>
    >> If you can't find one then the File System Object has methods to do
    >> this. The following code fragment illustrates the concept:
    >> Set oFSO = CreateObject("Scripting.FileSystemObject")
    >> dDate = oFSO.GetFile("d:\tools\att.vbs").DateLastModified
    >> WScript.Echo Year(dDate), Month(dDate), Day(dDate)
    >>
    >> You would need to write a script that enumerates every file in the
    >> folder and renames it with the rename method of the File System
    >> Object. Remember to pad your days and months with a leading zero if
    >> necessary and to deal with the case where two files might get the
    >> same name.
    >>
    >>
    >
    > Pegasus, thanks for the suggestions.
    > I have several file-renaming pieces of software - non of which have
    > sufficient logic to do what I want.
    > Regarding your code fragment; the DateLastModified is useless to me
    > since I need the date of original creation of the file; which is
    > recorded in the filename in the format ddmmmfilename1 etc.
    >
    > So I need to take the ddmmm part of the filename and re-insert it back
    > into the file name in the format mmddfilename1 etc. Obviously I can do
    > this with some clumsy manipulation along the lines of:
    > if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    >
    > but I was hoping to find out if there was some clever date recognition
    > function in VBS
    >
    Nope. You're on your own there. But it isn't that hard given that the namers
    of the files were faithful to this format. Simple string functions (Mid,
    Right and Left) will carry you through.

    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"



      My System SpecsSystem Spec

  7. #7


    Pegasus [MVP] Guest

    Re: How to Sort on Date in Filename?



    "Davy" <me@newsgroup> said this in news item
    news:Xns9CF6708FE96ACmeremoveallthistextc@newsgroup

    > "Pegasus [MVP]" <news@newsgroup> wrote in
    > news:OZaEAhSjKHA.5604@newsgroup:
    >

    >> "Davy" <me@newsgroup> said this in news item
    >> news:Xns9CF6622D5830Fmeremoveallthistextc@newsgroup

    >>> "Pegasus [MVP]" <news@newsgroup> wrote in
    >>> news:#I8TjnKjKHA.4048@newsgroup:
    >>>
    >>>> "Davy" <me@newsgroup> said this in news item
    >>>> news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup
    >>>>> I have files whose filenames include date created; with the
    >>> filename
    >>>>> format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >>>>>
    >>>>> In Windows Explorer I want to view the files in date sequence.
    > How

    >>>>> can I manipulate the ddmmm into a format that can be logically
    >>>>> sorted?
    >>>>>
    >>>>> thanks
    >>>>>
    >>>>> Davy
    >>>>
    >>>> Since you specifically mention Windows Explorer, I think you're
    >>>> posting in the wrong group. This group focuses on VB Scripting. A
    >>>> Windows XP (?) or a Windows file system newsgroup may be a better
    >>>> place. Anyway, since you named your files ddmmmFilename you have
    >>> three
    >>>> options: - Sort by dd (which is probably useless)
    >>>> - Sort by file date, by clicking the file date column header in
    >>>> Explorer. - Rename the files to yyyymmddFilename (where mm is the
    >>>> month *number*, not name).
    >>>>
    >>>>
    >>>
    >>> Pegasus, thanks for the prompt reply. I now realise that my post
    > was

    >>> not as clear as I imagined.
    >>> Although I want to use Windows Explorer to view the list of files,
    > I

    >>> want to use VBS to rename the files so that they can be sorted
    >>> meaningfully by date.
    >>> There are too many files to rename manually.
    >>> Unfortunately the files' 'date created' property does not reflect
    > the

    >>> date created; just the date these files were placed into their
    >>> current context.
    >>> I realise that I could write some VBS script along the lines of;
    >>> if mmm is 'Dec' then replace with '12', etc, etc. Then reformat
    > date

    >>> to mmdd so can be meaningfully sorted.
    >>> But I had hoped that there might be a VBS function that can parse a
    >>> date in the format ddmmm and recognise it and then another function
    >>> to convert it to a format that can be put into a file name for
    >>> sorting.
    >>>
    >>> Hope this makes sense, my VBS knowledge is somewhat limited.
    >>>
    >>> cheers, DAvy
    >>
    >> OK, I got misled by your subject line. It seems you wish to "rename"
    >> rather than to "sort" your files. If you put the words "bulk rename"
    >> into a Google search box then you will get a large number of hits
    > for

    >> renaming tools, many of the free. Some might actually do exactly
    > what

    >> you want to do.
    >>
    >> If you can't find one then the File System Object has methods to do
    >> this. The following code fragment illustrates the concept:
    >> Set oFSO = CreateObject("Scripting.FileSystemObject")
    >> dDate = oFSO.GetFile("d:\tools\att.vbs").DateLastModified
    >> WScript.Echo Year(dDate), Month(dDate), Day(dDate)
    >>
    >> You would need to write a script that enumerates every file in the
    >> folder and renames it with the rename method of the File System
    >> Object. Remember to pad your days and months with a leading zero if
    >> necessary and to deal with the case where two files might get the
    > same

    >> name.
    >>
    >>
    >
    > Pegasus, thanks for the suggestions.
    > I have several file-renaming pieces of software - non of which have
    > sufficient logic to do what I want.
    > Regarding your code fragment; the DateLastModified is useless to me
    > since I need the date of original creation of the file; which is
    > recorded in the filename in the format ddmmmfilename1 etc.
    >
    > So I need to take the ddmmm part of the filename and re-insert it back
    > into the file name in the format mmddfilename1 etc. Obviously I can do
    > this with some clumsy manipulation along the lines of:
    > if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    >
    > but I was hoping to find out if there was some clever date recognition
    > function in VBS
    >
    > cheeers
    >
    > DAvy
    There are three date methods in the File System Object:
    - DateLastModified
    - DateLastAccessed
    - DateCreated

    I recommend you download the helpfile script56.chm from the Microsoft site
    to see the full details.

    Depending on your exact setup you could also extract the day and month from
    the file name and the year from the DateCreated method. Translating month
    names into numbers is as clumsy or as elegant as you make it, e.g. like so:

    Set dicMonths = CreateObject( "Scripting.Dictionary" )
    aMonths = Split(LCase(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"))
    For i = 1 To 12
    if i < 10 then x = "0" & i Else x = i
    dicMonths.Add aMonths(i), x
    Next
    WScript.Echo "Month number = ", dicMonths(LCase("Mar"))



      My System SpecsSystem Spec

  8. #8


    Todd Vargo Guest

    Re: How to Sort on Date in Filename?

    Davy wrote:

    > So I need to take the ddmmm part of the filename and re-insert it back
    > into the file name in the format mmddfilename1 etc. Obviously I can do
    > this with some clumsy manipulation along the lines of:
    > if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    >
    > but I was hoping to find out if there was some clever date recognition
    > function in VBS
    You will have to create your own function. Feed the function an original
    filename. Use the Mid function to extract the month and convert it to
    numerals. Then construct the new name and return it to the function.

    Function ddmmm2mmdd(filename)
    mm = Right("0" & Month(Mid(filename, 3, 3) & "/1/00"), 2)
    ddmmm2mmdd = Left(filename, 2) & mm & Mid(filename, 6)
    End Function

    Now you simply use the new function in a loop.

    f.Name = ddmmm2mmdd(f.Name)

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


      My System SpecsSystem Spec

  9. #9


    Todd Vargo Guest

    Re: How to Sort on Date in Filename?

    Todd Vargo wrote:

    > Davy wrote:

    > > So I need to take the ddmmm part of the filename and re-insert it back
    > > into the file name in the format mmddfilename1 etc. Obviously I can do
    > > this with some clumsy manipulation along the lines of:
    > > if mmm is 'Dec' then replace with '12', etc, etc. Then reformat date
    > >
    > > but I was hoping to find out if there was some clever date recognition
    > > function in VBS
    >
    > You will have to create your own function. Feed the function an original
    > filename. Use the Mid function to extract the month and convert it to
    > numerals. Then construct the new name and return it to the function.
    >
    > Function ddmmm2mmdd(filename)
    > mm = Right("0" & Month(Mid(filename, 3, 3) & "/1/00"), 2)
    > ddmmm2mmdd = Left(filename, 2) & mm & Mid(filename, 6)
    Oops, I forgot to move the month to the front of the filename.
    Replace line above with this line.

    ddmmm2mmdd = mm & Left(filename, 2) & Mid(filename, 6)


    > End Function
    >
    > Now you simply use the new function in a loop.
    >
    > f.Name = ddmmm2mmdd(f.Name)
    >
    > --
    > Todd Vargo
    > (Post questions to group only. Remove "z" to email personal messages)
    >

      My System SpecsSystem Spec

  10. #10


    Davy Guest

    Re: How to Sort on Date in Filename?

    Davy <me@newsgroup> wrote in
    news:Xns9CF5B1C1ADEC1meremoveallthistextc@newsgroup:

    > I have files whose filenames include date created; with the filename
    > format ddmmmfilename2, ddmmmfilename3, etc in a folder.
    >
    > In Windows Explorer I want to view the files in date sequence. How can
    I

    > manipulate the ddmmm into a format that can be logically sorted?
    >
    > thanks
    >
    > Davy
    Thanks guys for the suggestions; look elegant enough for me. I was
    expecting to write reams of 'if' statements...

    I compromised with:

    Select Case dMonth
    Case "Jan"
    dMonth = "01"
    Case "Feb"
    dMonth = "02"
    etc

    thanks

    DAvy

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
How to Sort on Date in Filename?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Move n files sort by Filename Bals VB Script 8 09 Nov 2009
get-date - make it a filename IT Staff PowerShell 4 05 Nov 2008
Sort by date jayC Vista General 1 15 May 2008
Re: Can I sort within a sort, in folder view (eg., Name, Date) Baffin Live Mail 0 09 Dec 2007
Add Date and time to filename Jimbo PowerShell 4 11 May 2007