copyfile with date in the filename (1 Viewer)

miketamp

Registered User.
Local time
Today, 09:20
Joined
Mar 30, 2005
Messages
22
hi there
i use this code to copy a file from a source folder to the destination folder.

Code:
Dim myfolder$, myfoldertarget

myfolder = "C:\source\"
myfoldertarget = "c:\target\"

Dim fs As Object
Set fs = CreateObject("scripting.filesystemobject")
 fs.CopyFile (myfolder) & [mylistbox], [myfoldertarget], True

[Mylistbox] is a list in the form where the file name apears.
I want when the file is copied to add the current date to the file name
for example, if the file name in the source folder is "test.doc" in the destination must be "test10-01-2006.doc"

please help me
thanx...
 

Bat17

Registered User.
Local time
Today, 17:20
Joined
Sep 24, 2004
Messages
1,687
Assuming that the file is alway *.doc type then this should do it
fs.CopyFile (myfolder) & [mylistbox], [myfoldertarget] & Left([mylistbox], Len([mylistbox] - 4)) & Format(DATE, "DD-MM-YYYY") & ".doc", True

You may prefer to format the date as YYYY MM DD so that it sorts correctly in windows explorer though.

HTH

Peter
 

miketamp

Registered User.
Local time
Today, 09:20
Joined
Mar 30, 2005
Messages
22
hi there
thanx for the reply, but it doesn't work i have an run-time error '13' time mismatch. Can you please tell me why?
what about if it isn't a *.doc file but any file???

can you please help me?
thanx...
 

Bat17

Registered User.
Local time
Today, 17:20
Joined
Sep 24, 2004
Messages
1,687
ooops, sorry got the -4 in the wrong place
fs.CopyFile (myfolder) & [mylistbox], [myfoldertarget] & Left([mylistbox], Len([mylistbox]) - 4) & Format(DATE, "DD-MM-YYYY") & ".doc", True

If it is not .doc but it is always a 3 char suffix then you could change & ".doc" for & right([mylistbox],4)
If it is not always 3 then life gets a bit more complicated :)

HTH

Peter
 

Users who are viewing this thread

Top Bottom