Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: File renaming and removal to a subdirectory

by Abigail (Deacon)
on Jul 11, 2001 at 17:30 UTC ( [id://95674]=note: print w/replies, xml ) Need Help??


in reply to File renaming and removal to a subdirectory

# Subroutine that takes a filename of the form DDMM.xxx and returns # a filename of the form DDMMYYYY.xxx. sub alt_name { local $_ = shift; die "Illegal filename" unless my ($dd, $mm, $ext) = /^(\d\d)(\d\d) +.(.+)$/; my ($day, $month, $year) = (localtime) [3 .. 5]; $year += 1900; $month ++; if ($mm > $month || $mm == $month && $dd > $day) { # Assume file dates from last year. $year --; } sprintf "%02d%02d%04d.%s" => $dd, $mm, $year, $ext; }
As you see, the code doesn't add an 'A' or some other letter, but adds a year. It assumes that a date with a later month than the current month, or with a later day if the month is the current month is a file from last year (probably mostly important during your first run in January), else it's a file from this year. Of course, this scheme will fail if you wait more than a year between batches. But if you do, files in your Xwords directory might be overwritten anyway.

The reason I picked a year and not a letter is that otherwise you need to keep some state to see when you need to switch to the next letter. Now we just borrow the state from your OSses clock.

-- Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://95674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found