Here's what I need to do in a vbscript: If a certain file exists in a
directory, I need to copy it to the backup/archive directory adding the
date to the file name. Example - c:\files\filename.txt to
c:\archives\filename_20061211.dat.

I know how to do this is in DOS but not vbscript.

Thanks.

Chris

Re: need help by NY

NY
Mon Dec 11 14:43:27 CST 2006

youll use the FileExists method of the FileSystem object to see if the file
exists.
then you can use any number of Date() functions to return the current date
and time to append to your copied file, which youll do with the CopyFile
method (also of the filesystme object)

how far have you gotten so far?


<cclg2@yahoo.com> wrote in message
news:1165866898.995181.279940@80g2000cwy.googlegroups.com...
> Here's what I need to do in a vbscript: If a certain file exists in a
> directory, I need to copy it to the backup/archive directory adding the
> date to the file name. Example - c:\files\filename.txt to
> c:\archives\filename_20061211.dat.
>
> I know how to do this is in DOS but not vbscript.
>
> Thanks.
>
> Chris
>



Re: need help by cclg2

cclg2
Mon Dec 11 15:18:34 CST 2006

Not very far, I'm just learning vbscript. I guess it's time to find a
tutorial on the subject.
Thanks.

NY Steve wrote:
> youll use the FileExists method of the FileSystem object to see if the file
> exists.
> then you can use any number of Date() functions to return the current date
> and time to append to your copied file, which youll do with the CopyFile
> method (also of the filesystme object)
>
> how far have you gotten so far?
>
>
> <cclg2@yahoo.com> wrote in message
> news:1165866898.995181.279940@80g2000cwy.googlegroups.com...
> > Here's what I need to do in a vbscript: If a certain file exists in a
> > directory, I need to copy it to the backup/archive directory adding the
> > date to the file name. Example - c:\files\filename.txt to
> > c:\archives\filename_20061211.dat.
> >
> > I know how to do this is in DOS but not vbscript.
> >
> > Thanks.
> >
> > Chris
> >


Re: need help by Ayush

Ayush
Mon Dec 11 16:33:07 CST 2006

cclg2@yahoo.com wrote:
> Not very far, I'm just learning vbscript. I guess it's time to find a
> tutorial on the subject.
> Thanks.


'- - - - - - - - - - - - - -
Set objF = CreateObject("Scripting.FileSystemObject")
IF objF.FileExists("C:\files\filename.txt") Then
If objF.FolderExists("C:\Archives\") Then
objF.CopyFile "C:\files\filename.txt",
"c:\archives\filename_20061211.dat"
End If
End If
'- - - - - - - - - - - - - -

Here is the explaination :

1. '- - - - - - - - - - - - - -
2. Set objF = CreateObject("Scripting.FileSystemObject")
3. IF objF.FileExists("C:\files\filename.txt") Then
4. If objF.FolderExists("C:\Archives\") Then
5. objF.CopyFile "C:\files\filename.txt",
"c:\archives\filename_20061211.dat"
6. End If
7. End If
8. '- - - - - - - - - - - - - -


1. Starting line so that you know where to start the script.
It is in comment so it will not hurt anything even if you
include this in script.
2. Create the FileSystemObject to work with Files/Folders
(Copy,Move etc ... )
3. Check if "C:\files\filename.txt" exists or not. If it
exists then run the next line, if it doesn't exists then End
the if statement and continue the rest of script.
4. Check if "C:\Archives" folder exists or not. This is a
big thing, the script will not automatically create the
folder if it doesn't exists so it is good thing to check
instead of getting an error. If folder exists then contine
the next line, if doesn't then End this If statement.
5. Main thing : After checking all folder/files exists, run
the Copy operation. .. .
6. End the if statement that checks the Folder existence.
7. End the if statement that checks the File existence.
8. Ending line so that you know where the script ends. It is
in comment so it will not hurt anything even if you include
this in script.


More Info about FSO (File SYstem Object ) :
http://classicasp.aspfaq.com/files/directories-fso/could-i-get-some-help-working-with-files-using-filesystemobject.html

Some great explanation and examples of FSO :
http://www.computerperformance.co.uk/ezine/ezine36.htm

FSO Object :
http://www.computerperformance.co.uk/ezine/ezine104.htm




--
Ayush [ Good :-) Luck ]
-------------
Search - www.Google.com | Wikipedia -
http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------