Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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 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


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2014-09-23 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (234 votes), past polls