The question is marked as ASP classic but an algorithm solution is ok.
I have the following set of files which are sequentially numbered:
1.jpg, 2.jpg, 3.jpg, 4.jpg … X.jpg
I need a function which will take as input two filenames, the fromFile and toFile parameter, and which needs to rename all needed files in such a way that the from file is moved in the sequence before the toFile and the files in between renumbered.
Examples:
Moving 1.jpg onto 4.jpg should do the following:
- rename 1.jpg to 1.jpg.temp
- rename 2.jpg to 1.jpg
- rename 3.jpg to 2.jpg
- rename 1.jpg.temp to 3.jpg
- other files are unaffected by the operation
Moving 4.jpg to 2.jpg should do the following:
- rename 4.jpg to 4.jpg.tmp
- rename 3.jpg to 4.jpg
- rename 2.jpg to 3.jpg
- rename 1.jpg to 2.jpg
- rename 4.jpg.tmp to 1.jpg
- other files are unaffected
As input i have an array of strings containing filenames and the two filenames to/from.
Can you tell me what is the best approach to the file renaming?
Here is a brief approach, considering all your files will be named numeric.jpg, you’re going to have to build your own functions though:
FileExists(Filename)RenameFile(OriginalFilename,NewFilename)