Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: File renaming and removal to a subdirectory

by Abigail (Deacon)
on Jul 11, 2001 at 17:30 UTC ( #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 and returns # a filename of the form 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://95674]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-05-25 02:13 GMT
Find Nodes?
    Voting Booth?