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

I was writing a script to systematically change a set of files from one name
to another.  I was amazed to find out that the Copy() and CopyFile() only
allow you to make a copy of a file in a new directory, without the option to
give the file a new name.  In the end I had to resort to calling the "copy"
batch command using Shell.Run...which is dog slow.  Is there any
alternative??

Thanks,
Greg



Sun, 07 Jul 2002 03:00:00 GMT  
 Copy to file with new name...Copy() and CopyFile() inadequate
fso.Move is one method that you can investigate to do this...

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("c:\test.htm")
MyFile.Move "c:\test2.htm"

Vern
-
Vernon W. Hui
Microsoft Scripting Technologies
Software Test Engineer
http://msdn.microsoft.com/scripting


Quote:
> I was writing a script to systematically change a set of files from one
name
> to another.  I was amazed to find out that the Copy() and CopyFile() only
> allow you to make a copy of a file in a new directory, without the option
to
> give the file a new name.  In the end I had to resort to calling the
"copy"
> batch command using Shell.Run...which is dog slow.  Is there any
> alternative??

> Thanks,
> Greg



Sun, 07 Jul 2002 03:00:00 GMT  
 Copy to file with new name...Copy() and CopyFile() inadequate

The File.Name property is read/write.  To rename a file, get a File object reference to the file (for example with fso.GetFile("blah") or from the folder's Files collection) and simply set the File.name property to the new name.

--
Michael Harris


  I was writing a script to systematically change a set of files from one name
  to another.  I was amazed to find out that the Copy() and CopyFile() only
  allow you to make a copy of a file in a new directory, without the option to
  give the file a new name.  In the end I had to resort to calling the "copy"
  batch command using Shell.Run...which is dog slow.  Is there any
  alternative??

  Thanks,
  Greg



Sun, 07 Jul 2002 03:00:00 GMT  
 Copy to file with new name...Copy() and CopyFile() inadequate

Quote:

> I was writing a script to systematically change a set of files from one
name
> to another.  I was amazed to find out that the Copy() and CopyFile() only
> allow you to make a copy of a file in a new directory, without the option
to
> give the file a new name.  In the end I had to resort to calling the

"copy"

Actually, I was wrong...CopyFile() does do the trick.  The second argument
can be a file name, not just a directory.  Sorry for the disinformation!

Michael Harris' and Vernon W. Hui's replies were very helpful.  Thanks,
guys!

Greg



Tue, 09 Jul 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CopyFile Question - NT vs 95 - copying file from web site

2. Find a copy a file with File.Copy method

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

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

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

6. File Directory copy if files are newer

7. why i use fso.CopyFile can not copy to destination

8. dynamically copy all folder and file names ??

9. overwrite newer files only in copy

10. Copying only newer files

11. Assign mapped drive, copy files, for all new users

12. copy only NEW files

 

 
Powered by phpBB® Forum Software