Thread: Sweeper

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Sweeper


    Is it possible to create a perl program to

    1. continuously sweep a named directory for files with a certain extension and rename them with another extension?

    Example: continuously sweep \myfiles for files with the extension of .txt and rename them with the extension of .doc

    I have this need but I am thinking that it needs to be some type of continuous sweeper or continuous loop (while...)

    This is for both a Unix/Linux system or Windows.

    Thanks in advance.

    -Roger
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,971
    Rep Power
    1225
    Yes it is possible.

    So, now you should start working on writing the script and when you get stuck, post your code and a specific question.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    As a simple starting point, you could do something like this:

    Perl Code:
    while (1) {
         my @files = glob ("<directory>/*.<extension>");
         rename_files(@files) if defined @files;
         sleep 1; # waits 1 second before looping again.
    }



    You just have to write the rename_files() function, which needs to iterate over the filenames and rename them one by one.

IMN logo majestic logo threadwatch logo seochat tools logo