Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

Comment on Re: File renaming and removal to a subdirectory
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2015-10-07 13:34 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (185 votes), past polls