[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing name of file

Posted on 2006-05-10
5
Medium Priority
?
144 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:fnbgppl
5 Comments
 
LVL 1

Author Comment

by:fnbgppl
ID: 16653380
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
 
LVL 7

Accepted Solution

by:
Inteqam earned 1000 total points
ID: 16653507
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
 
LVL 9

Assisted Solution

by:Naveen Swamy
Naveen Swamy earned 1000 total points
ID: 16655542
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
 
LVL 1

Expert Comment

by:tushar_comp
ID: 16655883


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
 
LVL 1

Author Comment

by:fnbgppl
ID: 16693997
Thanks guys
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question