RaynMan has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, Fairly new to perl! I need to create a script that will move an entire user profile from the c: drive to a new drive location, such as the u: drive. This will include all types folders and their content. I need to move C:\Documents and Settings\Ryan-Laptop(user) to the new location without compromising any files. Is there a way to do it. I know file::Copy isn't what I'm looking for. Anything would be helpful. Thanks in advance!

  • Comment on Moving folders to new directory location

Replies are listed 'Best First'.
Re: Moving folders to new directory location
by BrowserUk (Patriarch) on Jun 23, 2010 at 21:55 UTC
    I need to move C:\Documents and Settings\Ryan-Laptop(user) to the new location without compromising any files.

    Then do as Corion suggested and use

    system q[xcopy /E /O /K C:\Documents and Settings\Ryan-Laptop(user) U: +\newName];

    as any other method (including Win32::CopyFile()), will compromise the files by not copying their security attributes (ACLs etc.).

    Read the help for xcopy to find out why /O is important. You might also want /X


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Nearly correct. We need to DOS-quote the argument, because of the embedded spaces.

      BTW, though not necessary in the concrete example, I think it would be a good idea to always use \\ instead of \ even withing q[...], because this will be needed anyway when directories are specified by using UNC pathes.

      -- 
      Ronald Fischer <ynnor@mm.st>
Re: Moving folders to new directory location
by Corion (Patriarch) on Jun 23, 2010 at 20:44 UTC

    Why do you think that File::Copy is not what you're looking for?

    Have you looked at the xcopy tool that comes with Windows?

      It needs to be writte in perl. It is an assigned task that I have recieved at work. Can I use File::Copy to move directories???

        Perl can launch xcopy using system.

        You will have to copy + delete anyways, so you can also use File::Copy and File::Path to delete the directories afterwards. Although when deleting things, I hope you have good and tested backups.