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

I am a semi-newbie and I was wanting to write a script that reads a list of folder names from an excel file or text file, doesnt really matter, and it reads in those names and matches those names with folder names in a directory. If there is a match I want it to move the entire folder in that directory and place it in another directory. Or it could place that folder in another folder in the same directory which ever would be easier. Does this sound do-able? If so could someone point me in the right direction with a good tutorial or a few good code snippets. Ive already looked at working with directories but just opening and reading them couldnt find anything about moving folders and their contents anywhere. The folder is on a server that resides on a NT machine. I can access the folder from my client machine with runs windows xp pro. I would rather run the script from my machine so I dont have to install perl on the server. Thanks

Replies are listed 'Best First'.
Re: Moving folders
by chas (Priest) on Mar 09, 2005 at 16:43 UTC
    One comment: There are operating system commands to move files/directories, so if you know what you want to move you can use use system to manage that.
    chas
Re: Moving folders
by ww (Archbishop) on Mar 09, 2005 at 16:49 UTC
    excel is MS. "folders" sounds windows-ish. But is the machine where you want to do this a windows box?
    (suggest you answer by updating original).

    sounds trivial as shell script under *n*x; definitely do-able w/perl on windows.

      The folder is on a server that resides on a NT machine. I can access the folder from my client machine with runs windows xp pro. I would rather run the script from my machine so I dont have to install perl on the server. Thanks
Re: Moving folders
by goober99 (Scribe) on Mar 09, 2005 at 20:25 UTC
    Using system, this is how you can do it on Windows:
    $defaultdir = 'C:\Foo\'; # Directory containing original folders $destinationdir = 'C:\Bar\'; # Directory to copy folders to system "move /y $defaultdir/$matchedfolder $destinationdir";
    You could place this within a loop that reads each line and places the matched folder name in $matchedfolder. The /y just keeps a overwrite confirmation box from popping up. If you would like to be warned before overwriting files remove /y.

    I don't see any reason you couldn't run this from your XP computer and move files on your NT server. Just map the directories you are working with and use M:/ or whatever drive letter you designate in the path variables.
      As I said I am pretty new at this so I am sure I am missing something but i tried this code just to test it out
      #!/usr/bin/perl

      $defaultdir = 'C:\Documents and Settings\Tim\My Documents\test1'; # Directory containing original folders
      $destinationdir = 'C:\Documents and Settings\Tim\My Documents\test2'; # Directory to copy folders to
      $matchedfolder ='foo'; # a folder name in test1

      system "move /y $defaultdir/$matchedfolder $destinationdir";

      i run it and i get the msg
      "The syntax of the command is incorrect"

        Here we're dealing with two programs: perl and move. Actually, on Windows, I think move is merely part of CMD.EXE. You need to format your input into move from perl such that move (or CMD.EXE) understands it. And it doesn't get spaces properly.

        system qq(move /y "$defaultdir/$matchedfolder" "$destinationdir");

        Perl makes this so much easier than doing the same thing in other languages, such as C or Java. SOOOO much easier with that qq operator.