Find a copy a file with File.Copy method 
Author Message
 Find a copy a file with File.Copy method

I have a VBScript that I use to parse all log the files in a directory to
find the log file created yesterday (using DateCreated property). The script
currently zips the logs, but I want to change that.

Once the file has been found, I want to copy it locally to a different
directory and rename it in the process. I know how to use File.Copy when I
already know file name, but how to I tell File.Copy to copy the file when
the I can't give it an explicit name??

(the log file has a different name every day)

Here is the code

On error resume next

Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set RootFolder = FileSystem.GetFolder(RootDir)

RootDir = Wscript.Arguments(0)

Set SubFiles = RootFolder.Files

For Each File in SubFiles

SourceFile = File.DateLastModified

If SourceFile = ((Date()) -2) Then TargetFile.Copy "c:\DestFile.csv",1

Next



Fri, 21 May 2004 07:58:43 GMT  
 Find a copy a file with File.Copy method
In your For loop, File.Name is the name of the file and
File.Path is the full name including path.

Perhaps you can use
FileSystem.CopyFile File.Path "c:\destfile.csv"

Richard

Quote:
>-----Original Message-----
>I have a vbscript that I use to parse all log the files
in a directory to
>find the log file created yesterday (using DateCreated

property). The script
Quote:
>currently zips the logs, but I want to change that.

>Once the file has been found, I want to copy it locally
to a different
>directory and rename it in the process. I know how to use
File.Copy when I
>already know file name, but how to I tell File.Copy to
copy the file when
>the I can't give it an explicit name??

>(the log file has a different name every day)

>Here is the code

>On error resume next

>Set FileSystem = CreateObject

("Scripting.FileSystemObject")
Quote:
>Set RootFolder = FileSystem.GetFolder(RootDir)

>RootDir = Wscript.Arguments(0)

>Set SubFiles = RootFolder.Files

>For Each File in SubFiles

>SourceFile = File.DateLastModified

>If SourceFile = ((Date()) -2) Then

TargetFile.Copy "c:\DestFile.csv",1

- Show quoted text -

Quote:

>Next

>.



Fri, 21 May 2004 09:20:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Need help finding method for copying files from Internet

2. Copy multiple files and checking if all files are copied

3. --- copying a PostSctipt file with the DOS COPY command

4. Copy a file in a folder and past the copy in another folder

5. Copy to file with new name...Copy() and CopyFile() inadequate

6. how to use Volume Shadow Copy to copy an in use file

7. Copy a bunch of files but can't cancel in the middle of copy

8. copy folder and copy files

9. problems with copy method of file object

10. What's the best method of copying files on the net

11. Fastest file copy method

12. an api method to copy an open file?

 

 
Powered by phpBB® Forum Software