troubleshooting Question

Change file name and date created in batch or script

Avatar of thenelson
thenelson asked on
Scripting LanguagesWindows BatchVB Script
5 Comments1 Solution472 ViewsLast Modified:
I have several thousand files with the following name format:

Doe, Jane 2006-02-25

I wish to rename all the files stripping the date and setting the file created date to the date in the name. For the example above:

File name:   Doe, Jane              Date created 02-25-2006

Here is a piece of VB script I wrote but I am having problems with the lines that change the file name and create date:

Dim FileName As String, NewFileDate As String, NewFileName As String
Dim pos As Integer

ChDir "\Temp1"
FileName = Dir("\temp1\*.*")
While FileName <> ""
    pos = InStrRev(FileName, " ")
    NewFileName = Left(FileName, pos - 1)
    Trim NewFileName
    NewFileDate = Mid(FileName, pos + 1)
    NewFileDate = Left(NewFileDate, Len(NewFileDate) - 4)
    Debug.Print FileName, "]" & NewFileName & "[", "]" & NewFileDate & "["
    '***** Shell "ren """ & FileName & """ """ & NewFileName & ""  *****   PROBLEM HERE
    '***** Shell "Touch """ & NewFileName & """ /d:" & NewFileDate   ***** PROBLEM HERE
    FileName = Dir
Wend

Can someone either help me with my code or provide a different approach?

Thanks!
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004