Bulldog98
asked on
VBScript needed to copy a file to a new folder and append a UK datestamp to the filename.
Hi,
I require a VBScript that will copy a file from one folder on the computer to another folder and then rename the file by adding a datestamp in UK format. I have looked around but the only ones I seem to be able to find are designed to run on computers with a US locale.
If possible the script would detect the systems locale that it is running on so that it would work on UK and US locale systems and maybe also the ability to copy the file to a different system as well.
Example:
Copy file from C:\MyFolder\MyFile.txt to C:\MyBackup\MyFile_2007-12 -31.txt
Thanks in advance.
I require a VBScript that will copy a file from one folder on the computer to another folder and then rename the file by adding a datestamp in UK format. I have looked around but the only ones I seem to be able to find are designed to run on computers with a US locale.
If possible the script would detect the systems locale that it is running on so that it would work on UK and US locale systems and maybe also the ability to copy the file to a different system as well.
Example:
Copy file from C:\MyFolder\MyFile.txt to C:\MyBackup\MyFile_2007-12
Thanks in advance.
ASKER
Thanks for the quick response but when executing that script I receive the following error:
Line: 9
Char: 1
Error: Type mismatch: 'Format'
Code: 800A000D
Thanks
Line: 9
Char: 1
Error: Type mismatch: 'Format'
Code: 800A000D
Thanks
how about this one
Dim FSys
Dim MyFile, DestFolder
Dim DestFile
MyFile="C:\MyFolder\MyFile.txt"
DestFolder="C:\MyBackUp\"
Set FSys = CreateObject("Scripting.FileSystemObject")
DestFile= DestFolder & FSys.GetBaseName(MyFile) & "_" & Year(Date) & "-"
if Month(Date)<10 then DestFile= DestFolder & "0"
DestFile= DestFolder & Month(Date) & "-"
if Day(Date)<10 then DestFile= DestFolder & "0"
DestFile= DestFolder & Day(Date) & "." & FSys.GetExtension(MyFile)
FSO.CopyFile MyFile, DestFile
ASKER
Sorry, that does not work either. :(
Line: 13
Char: 1
Error: Object doesn't support this property or method: 'GetExtension'
Thanks
Line: 13
Char: 1
Error: Object doesn't support this property or method: 'GetExtension'
Thanks
can you try this?
Dim i
Dim FSys
Dim MyFile, DestFolder
Dim FName, FExt
Dim DestFile
MyFile="C:\MyFolder\MyFile.txt"
DestFolder="C:\MyBackUp"
Set FSys = CreateObject("Scripting.FileSystemObject")
FExt=""
for i=len(myfile) to 1 step -1
FExt= mid(myfile,i,1) & FExt
if mid(myfile,i,1)="." then exit for
next
FName=""
for i=len(myfile)-len(FExt) to 1 step -1
FName= mid(myfile,i,1) & FName
if mid(myfile,i,1)="\" then exit for
next
DestFile= Mid(MyFile,Instr(MyFile,
DestFile= DestFolder & FName & "_" & Year(Date) & "-"
if Month(Date)<10 then DestFile= DestFolder & "0"
DestFile= DestFolder & Month(Date) & "-"
if Day(Date)<10 then DestFile= DestFolder & "0"
DestFile= DestFolder & Day(Date) & "." & FExt
FSys.CopyFile MyFile, DestFile
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help, everything is working now.
try this code out
just change MyFile and DestFolder to change the file to be copied and the destination folder.
Open in new window