: Thanks a lot for your help. For some reason, WSH (at least under
Win95)
: doesn't like when you use a variable for the destination folder. I
even
: tried putting the backslash at the end of the getFolder line and it
didn't
: work. Does anyone know why this doesn't work?
There shouldn't be a problem using variables for the destination
folder, provided that it's a valid, existing folder. Putting a
backslash at the end of the getFolder line will only work if you don't
use the SET statement. The SET statement retrieves the folder as an
object, which by design doesn't include a trailing backslash. If you
just assign a variable to the getFolder line, you can then attach any
string that you want to the variable. However, the variable will
merely be a string, not an object with properties (which doesn't
matter in this case).
: However, it seems that the final backslash doesn't matter.
Esposito's book
: (the Wrox book) states on p. 145: "The destination is the name of a
folder
: that you can force to be created by not adding a final backslash."
So, if
: the folder that you are trying to copy to doesn't exist, apparently
it will
: be created.
The book is wrong (not its only error). If you omit the final
backslash, then the Copyfile method will attempt to create a file as
the destination, not a folder. If that filename already exists as a
file or folder you will get a run-time error, which is what happened
to you.
: Originally I had used the wildcards to copy the files, but if there
were no
: files to be found (and just subdirectories), I got a "file not
found"
: error. Very strange.
:
The CopyFile method and most of the rest of the FSO methods and
properties will throw a runtime error if you ask them to process a
file or folder that doesn't exist, whether or not you use wildcards.
To avoid this sort of error when using wildcards, use the Count
property of the Files collection beforehand to verify that at least
one file exists.
: Thanks again and best regards!
:
: >
: > Eliminate the following line:
: > set tempFold = fso.getFolder("C:\temp\copydisk")
: >
: > Change the line that reads:
: > fso.CopyFile DiskFile, tempFold
: >
: > to read:
: > fso.CopyFile DiskFile, "C:\temp\copydisk\"
: >
: > Note the backslash at the end of the folder name. It is mandatory
when
: > the target of the copy operation is a folder.
: >
: > Of course, you could take another approach altogether:
: >
: > set fso = WScript.CreateObject("Scripting.FileSystemObject")
: > fso.CopyFile "a\*.*", "C:\temp\copydisk\"