Changing name of file

I have the following script that just copies a file to another directory.  I want to rename this file with a date stamp or something of the sort.  This is being used as backup storage, so if I could get it to go on a two week cycle that would be great.  Any help with this would be greatly appreciated.

FNBGPPL
LVL 1
fnbgpplAsked:
Who is Participating?
 
InteqamConnect With a Mentor Commented:
on error resume next
dim fso
dim filename

const sourcefolder = "M:\testfrom"
const destfolder = "C:\"
set fso = createobject("Scripting.Filesystemobject")
set folder = fso.getfolder(sourcefolder)
set tofolder = fso.getfolder(destfolder)
for each file in folder.files
     filename = trim(file.name) & year(date) & Month(date) & day(date)
     file.copy destfolder & "\" & filename
if err.number = 58 then
file.copy destfolder & "\" & filename & "-1"
end if

file.copy sourcefolder & "\" & filename
next
0
 
fnbgpplAuthor Commented:
on error resume next
dim fso
dim filename

const sourcefolder = "M:\testfrom"
const destfolder = "C:\"
set fso = createobject("Scripting.Filesystemobject")
set folder = fso.getfolder(sourcefolder)
set tofolder = fso.getfolder(destfolder)
for each file in folder.files
     filename = trim(file.name)
     file.copy destfolder & "\" & filename
if err.number = 58 then
file.copy destfolder & "\" & filename & "-1"
end if

file.copy sourcefolder & "\" & filename
next
0
 
Naveen SwamyConnect With a Mentor Yash Infinite Solutions Private LimitedCommented:
fso code to copy the files are already posted, you just need to compare the dates for 2 week cycle with datediff thst it you are done


If DateDiff("d", datetimetocompare, Date) > 14 Then '*****2 weeks comparision*****
     '*****Do your copy thing here*****
end if
0
 
tushar_compCommented:


hi,
use constant to store date when the program started
then use datediff function to check for the two weeks
use date data type for getting time like time()
then append this to the filename

Tushar

0
 
fnbgpplAuthor Commented:
Thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.