Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Incrementing file extensions
I'm stuck (again). Here is my problem: I need to store files which a user uploads to the server in a specified directory and with a 'sensible' name, ie one that I create. What I want to do is create a script which does all the naming for me. Basically all the files will have the same prefix, it will only be the ending which will be different. For example:
Notice the increment (1, 2, 3, 4). How would I do this? I have made an attempt at this but I'm unsure as to how I would continue. Here are some ideas which I have so far:
1. Change to the correct directory for files.
2. Read all of the files in the directory and see what
the increment is currently at eg 4 for TXT4.
3. Rename the uploaded file to the filename which is one more than
the last eg TXT5.
2.1 Split the names of the files into separate parts, the prefix (TXT)
and the suffix (increment number). Find the highest suffix and
3.1 Create the filename by concatenating TXT and the increment number
I know that Perl is good for this sort of thing, so this message is cross-posted to the Perl forum.
Many thanks for all help and suggestions.