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

Hello, I am new to perl and am looking to solve a problem. I have a bunch of files in a directory on my E drive in /E/temp. These files are of the format USWT2A(2digityear).(dayofyear) I need a perl script that can read each file in the directories year and day of year from the filename and put it into the directory /E/year/dayofyear and if that directory doesnt exist, create it. Once the copy is completed successfully it needs to delete the files from ?E/temp. This is something that needs to run on my windows box once a day. Can someone help me?

Replies are listed 'Best First'.
Re: Perl for windows file parsing
by Fletch (Bishop) on Oct 12, 2007 at 20:38 UTC
Re: Perl for windows file parsing
by TGI (Parson) on Oct 12, 2007 at 21:13 UTC

    Here's an outline of your program:

    open directory handle for E:\temp while the handle returns filenames match filename against spec. - capture year and day of year. if name does not match, skip to the next file. test for existence of target path. if does not exist, create it. move file to new location.

    Between the outline above and Fletch's pointers to docs you should be able to put something together.

    You should also take a look at next. perlretut will help you match the filenames to your spec and capture the information you want.

    Once you have a script that works, you can create an entry in Scheduled Tasks.

    Also worth mentioning, many tutorial neglect to suggest using strict, warnings and diagnostics. I strongly recommend using all 3 when starting out. diagnostics can be skipped after you've learned to interpret Perl's compiler alerts.


    TGI says moo