Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move folders

Status
Not open for further replies.

loganmex

Programmer
Nov 14, 2001
17
MX
I have one folder (call it Folder1), with several subfolders inside, each one with several files in them. I want to move everything inside Folder1 to Folder2 (which is empty, but exists).

I've been trying MoveFolder, but I get a "file doesn't exist error" all the time, and the descriptions don't give any examples of using wildcards or what happens if a folder is not empty.

My script is basically:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.Movefolder "c:\Folder1\*", "c:\Folder2\"


What can I do?
 
fso.Movefolder "c:\Folder1\", "c:\Folder2\"

remove the star wildcard, you are moving folder1 it will take it all with it.
 
Thanks spazman

But if I do that I get a "Path not found" error, instead of the "File not found" error =(.
 
try dropping the \ from the end of the folder strings?
 
Try something like this:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder "c:\Folder2"
fso.Movefolder "c:\Folder1", "c:\Folder2"
NB: Verify that folder2 is really empty before to run this script.


Hope This Help
PH.
 
If source contains wildcards or destination ends with a path separator (\), it is assumed that destination specifies an existing folder in which to move the matching files. Otherwise, destination is assumed to be the name of a destination folder to create. In either case, three things can happen when an individual folder is moved:

If destination does not exist, the folder gets moved. This is the usual case.
If destination is an existing file, an error occurs.
If destination is a directory, an error occurs.

so i guess if you drop the \ at the end of the destination you will be ok
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top