Jump to content

Moving or Copying Directories


Recommended Posts

It would be really nice if there were a DirCopy or DirMove command, that would let you copy (or move) an entire directory, plus all of it's files and sub-folders in one easy step. The help file states that the FileMove function can move directories, but I have not been able to get that to work at all. I don't know if it's a bug, or if it's just to painfully obvious for me to see how to do it. Anyone have any ideas how I could do this? Thanks!

Link to post
Share on other sites

The windows dir command might help....

Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

Also, see xcopy

Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites

....., the XCOPY command would work perfectly to copy those files.

Beware though that xcopy behaves differently in NT4 W2k and XP, in case your script has to work on multiple systems. Of particular significance is /Y which is not understood by NT4, as well as that xcopy on NT4 keeps asking if the file to be copied is a file or a directory if folders do not exist in advance.

I found it the hard way. :whistle:

regards

niranjan

Link to post
Share on other sites
  • Administrators

I'm sure that when I tested the FileMove command it happily moved/renamed entire directories. I'll have to recheck.

Edit:

Yeah, FileMove works here moving entire directories and any sub directories/files.

Link to post
Share on other sites

One thing I didn't see anybody mention is that all directories along the path you are moving to have to exist or FileMove won't do anything. For example, given this directory structure:

C:\Folder To Move

C:\Another Folder

FileMove("C:\Folder To Move", "C:\Another Folder\Moved Here")

The above works, "Folder To Move" will be moved and renamed.

FileMove("C:\Folder To Move", "C:\Another Folder\Sub\Not Moved")

This will not work since the directory "Sub" doesn't exist. FileMove returns 1 to indicate failure. Maybe you were trying to do something like the above and that's why FileMove wouldn't work?

Link to post
Share on other sites
  • 1 month later...

Hey, thanks for all the help. Yes, I was trying to use the move command to move a specific folder (such as "C:\Program Files\My Program\*.*"), and all it's subdirectories, to a new folder such as "\\Server Name\Share Name\Backups".

I was hoping it would also move (or create) empty folders, and also move any files that had the Read-Only attribute set. I believe the problem was that any Read-Only files would not be copied/moved correctly.

I haven't tried this with the new beta 90 release yet however.

Thanks again!

Jeff

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...