rename a folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

rename a folder

#1 Post by Mohammad_Dos » 16 Feb 2012 11:53

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

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: rename a folder

#2 Post by Squashman » 16 Feb 2012 12:28

Can I see the code you tried to use?

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: rename a folder

#3 Post by Mohammad_Dos » 16 Feb 2012 13:29

i dont have any idea. in fact, this is not my question. somebody else asked this. can anyone help?

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: rename a folder

#4 Post by !k » 16 Feb 2012 13:52

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: rename a folder

#5 Post by foxidrive » 16 Feb 2012 20:59

Does only one folder exist in the directory? Or should the batch file keep track of the name of the folder?

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: rename a folder

#6 Post by Squashman » 17 Feb 2012 07:33

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: rename a folder

#7 Post by foxidrive » 17 Feb 2012 08:59

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.

Post Reply