PDA

View Full Version : copy files (WNT)



chrisleeds
05-14-2002, 11:27 AM
I have writen the following script but I can not get the testfile.txt to move in to the BackUp dir. I am new to this so its probibly something simple I am missing.


'*** Little Script to check if a file exists ***

'*** Declare the variables ***
Dim fso, tf, MyDate, BackUp

'*** Use the file System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'*** Get the Current Date **
CurrentDate = Date
MyDay = Day(CurrentDate)
MyMonth = Month(CurrentDate)
MyYear = Year(CurrentDate)
MyDate = MyDay & "-" & MyMonth & "-" & MyYear

'*** Create backup folder ***
Set BackUp = fso.CreateFolder("C:\" & MyDate)

'*** Check the file exists ***
If (fso.FileExists("c:\testfile.txt")) Then

'*** Create a file if it exists and write an success message to it ***
Set tf = fso.CreateTextFile("C:\" & MyDate & ".txt",True)
tf.WriteLine ("the file c:\testfile.txt exists and can be used at your lesure")
tf.close

'*** Copy TestFile.txt to the Backup Folder (The Bit that does not Work)
fso.CopyFile "c:\testfile.txt", "BackUpDir"

Else

'*** Create a error file if it does not exist and write a message to it
Set tf = fso.CreateTextFile("C:\" & MyDate & " " & MyTime & ".txt",True)
tf.WriteLine ("Help, file c:\testfile.txt does not exist, where is it?")
tf.close

End If

chrisleeds
05-14-2002, 11:42 AM
After a bit of messing a round I have changed the problem Line to the Following which should work. I get a Permission Denied message now.

(Changed Line)
'*** Copy TestFile.txt to the Backup Folder
fso.CopyFile "c:\testfile.txt", ("C:\" & MyDate)

chrisleeds
05-14-2002, 12:40 PM
Fixed (see code below). Thought I would tell you how in case anyone else is having the same problems.
'*** Copy TestFile.txt to the Backup Folder
fso.CopyFile "c:\testfile.txt", ("C:\" & MyDate & "\")

Added the & "\" and it now works a treat