Collections 
Author Message
 Collections

I'm having a problem with copying files, and it may have to do with access
control.  All I would like to do is copy a bunch of files from a floppy
disk to a temporary folder.  I continuously get the error message,
"Permission access denied".  Am I doing something incorrectly, or is this
something you just can't do?  Thanks!

Ed

P.S. My speculation is that when you access a collection object, the
files/folders are locked so you can't move them or copy them elsewhere.
----------

set fso = WScript.CreateObject("Scripting.FileSystemObject")
set afold = fso.getFolder("A:\")
set tempFold = fso.getFolder("C:\temp\copydisk")
...
for each DiskFile in afold.Files
   WScript.Echo DiskFile
   fso.CopyFile DiskFile, tempFold       ' This is where the error lies
next



Fri, 13 Sep 2002 03:00:00 GMT  
 Collections

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\"


I'm having a problem with copying files, and it may have to do with
access control.  All I would like to do is copy a bunch of files from
a floppy disk to a temporary folder.  I continuously get the error
message, "Permission access denied".  Am I doing something
incorrectly, or is this something you just can't do?  Thanks!
Ed
P.S. My speculation is that when you access a collection object, the
files/folders are locked so you can't move them or copy them
elsewhere.
----------
set fso = WScript.CreateObject("Scripting.FileSystemObject")
set afold = fso.getFolder("A:\")
set tempFold = fso.getFolder("C:\temp\copydisk")
...
for each DiskFile in afold.Files
   WScript.Echo DiskFile
   fso.CopyFile DiskFile, tempFold       ' This is where the error
lies
next



Sat, 14 Sep 2002 03:00:00 GMT  
 Collections
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?

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.

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.

Thanks again and best regards!

Quote:

> 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\"



Sat, 14 Sep 2002 03:00:00 GMT  
 Collections


: 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\"



Sun, 15 Sep 2002 03:00:00 GMT  
 Collections

Try Something like this

dim fso, strSource, strDest
set fso = createobject("Scripting.FileSystemObject")
strSource = "A:"
strDest = "C:\Temp\CopyDisk"
fso.CopyFolder strSource, strDest

The problem is that the function isn't looking for an object, but rather a string of the path.

hope this helps

  I'm having a problem with copying files, and it may have to do with access control.  All I would like to do is copy a bunch of files from a floppy disk to a temporary folder.  I continuously get the error message, "Permission access denied".  Am I doing something incorrectly, or is this something you just can't do?  Thanks!
  Ed

  P.S. My speculation is that when you access a collection object, the files/folders are locked so you can't move them or copy them elsewhere.
  ----------

  set fso = WScript.CreateObject("Scripting.FileSystemObject")
  set afold = fso.getFolder("A:\")
  set tempFold = fso.getFolder("C:\temp\copydisk")
  ...
  for each DiskFile in afold.Files
     WScript.Echo DiskFile
     fso.CopyFile DiskFile, tempFold       ' This is where the error lies
  next



Fri, 04 Oct 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How do I/Can I Create a collection object in vbscript/asp

2. web besed data collection

3. Working with collections in html forms

4. How to create collection in VBScript, precisely in a vbscript class

5. programmer defined collections in VBScript

6. Collections in ASP

7. Loop through Items collection

8. Collection of answears to Lit. about PostScript

9. accessing items of a field-collection via vbscript

10. Where is the collection of browser windows?

11. collections in custom classes

12. free threaded collection for asp + vbscript

 

 
Powered by phpBB® Forum Software