Rename all files in directory with oldname plus date

E

Eric Blitzer

I have a specified directory where I want to rename the
files with the old name plus the date. I want to do this
with one click of a command button on a form. The number
of files changes anywhere from 1 to 100. Does anyone know
the code that will loop through all the files?

Thanks for your help


Eric
 
W

Wayne Morgan

Successive calls to Dir without any parameters will continue to call the
next file meeting the original parameter. Do this until Dir returns "".

strFileName = Dir "<path>\*.*"
Do Until strFileName = ""
Name "<path>\" & strFileName As "<path>\" & strFileName & Format(Date,
"yyymmdd")
strFileName = Dir
Loop

Replace <path> with the actual path to the folder.
 
E

Eric Blitzer

Thanks Wayne but I am getting a syntax error on the first line

strFileName = Dir "c:\newfiles\*.*"

Do I have this right

Thanks again
Eric
 
R

Rick Brandt

Eric Blitzer said:
Thanks Wayne but I am getting a syntax error on the first line

strFileName = Dir "c:\newfiles\*.*"

Do I have this right


strFileName = Dir("c:\newfiles\*.*")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top