Yes there is a dependency on the $GetName value because that is what the user is going to input for the program to use as a search criteria when it scans the directory for files. The $StarCh and $EndCh are basically chapter numbers. starting and ending chapters. Each of these files that will be in the directory The files will have the chapter number within the file name somewhere. For example "Test_001.txt" will be chapter 1 file but depending on who created the files, someone could have a totally different naming convention such as "Ch 1 title 3rd edition". Something like this will throw off my whole program and thats where I need the program to be more robust. I need code to handle many possibilities. Now thinking about it, maybe there isnt a way for to actually code all possibilties. Thanks for your input and some of your suggestions does help me for what its worth. Thanks!
Using your code:
my $digit_width = 4; # This isnt necessarily true every time
my $min = 1;
my $max = 12;
my $prefix = "test_";
my $ext = ".txt";
while ( my $file = readdir DIR ) {
next unless ( $file =~ /^ $prefix (\d{$digit_width}) $ext $/x );
if ( $1 >= $min and $1 <= $max ) {
# we have a match... now now we want to create the new file na
+me
# Whatever $SetName was so if $SetName = "Chapter \1" which me
+ans
# The new file name for the program to modify in the directory
+ is
# to "Chapter 01.txt" for the 1st chapter file which wouldve b
+een
# Test_001.txt in the directory it searched in. I will then
# have the code rename the file.
}
}