Keep It Simple, Stupid | |
PerlMonks |
Re: Automatically creating incremental file namesby richardX (Pilgrim) |
on May 28, 2003 at 02:45 UTC ( [id://261191]=note: print w/replies, xml ) | Need Help?? |
Here is a snippet from a program that I use daily that checks for a duplicate file name in the out bucket and renames the in bucket filename if it already exists.
$fn_in is the directory for the in bucket of file names. $fn_out is the directory for the out bucket of file names The critical line is a self incrementing line until it finds a file name that does not exist in the out bucket. $fname_new = sprintf "$name-%02d$ext", $i; The format of the file name will be FILENAME-NN.EXT where NN is an incrementing number. You can easily customize this to your likes. I like using this solution because it works on all platorms and does not require any overhead or modules. Richard
In Section
Seekers of Perl Wisdom
|
|