i want to rename a folder. the batch file must replace X with a random number(from 1 to 100). and when i run it again , the name change with another number
folderX ----> folder22 ----> folder68
rename a folder
Moderator: DosItHelp
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
Re: rename a folder
Can I see the code you tried to use?
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
Re: rename a folder
i dont have any idea. in fact, this is not my question. somebody else asked this. can anyone help?
Re: rename a folder
Code: Select all
set name=folder
set /a next=%random% %% 100
move %name%* %name%%next%
Last edited by !k on 17 Feb 2012 12:03, edited 1 time in total.
Re: rename a folder
Does only one folder exist in the directory? Or should the batch file keep track of the name of the folder?
Re: rename a folder
foxidrive wrote:Does only one folder exist in the directory? Or should the batch file keep track of the name of the folder?
I was kind of thinking the same thing.
But regardless of that it seems like you would need extra logic for the first time the script runs just so that is Changes the X at the end of the folder name to a number the first time. After that you would always be changing an undefined number size at the end of the folder name. Could be Folder100, Folder99 or Folder1. Which again shouldn't be that big of a deal either. You can just use string substitution to get rid of all the numbers at the end of the name. But then we also would not know if the folder name has any other numbers in it that need to be kept.
What if the original Folder name was one of these combinations
Folder12X
Folder2X
Folder123ABCX
This is one of my biggest gripes with writing scripts for people. Never knowing what their input to the script really is. Always hard to take into account all possibilities they will throw at it.
Re: rename a folder
Squashman wrote:This is one of my biggest gripes with writing scripts for people. Never knowing what their input to the script really is.
Usually, I'll either ask for some info if it is too ambiguous or write something to exercise the grey matter, if it seems reasonable.
From experience in other groups, often the OP doesn't reply so you never find out if it worked or not anyway.