#1 04 Aug 2016 14:42

Ehbraheem
New Member
Registered: 04 Aug 2016
Posts: 4

windows batch rename folder with the old name stripping out character

I want to rename a folder of this type of name   

abc-cde-1.2.3_4

to 

1.2.3_4

. I'm new to batch

Offline

#2 04 Aug 2016 15:00

Aacini
Member
Registered: 05 Dec 2012
Posts: 118

Re: windows batch rename folder with the old name stripping out character

You must be more precise in the details of your problem. Otherwise, this is a valid solution to your question:

ren abc-cde-1.2.3_4 1.2.3_4

Antonio

Offline

#3 04 Aug 2016 15:02

Ehbraheem
New Member
Registered: 04 Aug 2016
Posts: 4

Re: windows batch rename folder with the old name stripping out character

Thanks. I mean I want to programmatically rename it. Cos the version number might change anytime.

Offline

#4 04 Aug 2016 17:12

Aacini
Member
Registered: 05 Dec 2012
Posts: 118

Re: windows batch rename folder with the old name stripping out character

Have you a folder with a name of this form: "xxx-yyy-zzz" and you want to rename it to just "zzz"? That is: is the name comprised of precisely three parts separated by dash and the new name is the last part?

Is there just one folder with this name format? May be more folders? What to do in this case?

[Please: do NOT reply "Yes". Copy this text and rephrase it so you correctly describe your problem. Note that your last reply did NOT explained why "ren abc-cde-1.2.3_4 1.2.3_4" is not a valid solution for your problem: "the version number might change anytime" means nothing for us!]

Antonio

Offline

#5 04 Aug 2016 17:28

Ehbraheem
New Member
Registered: 04 Aug 2016
Posts: 4

Re: windows batch rename folder with the old name stripping out character

Silly me. Thanks anyway. I have a folder of name in form 

abc-cde-1.2.3_4

and I am writing a cmd script against it. I want to rename it to form

1.2.3_4

only the last part. Or striping it to be wherever the digit begin. I have tried stuff like

ren "abc-cde-*" "*"

but the wildcard rename the folder to the same name. I want the script to be able to work incase someone else have a folder of kind

abc-cde-1.2

for future preference

Offline

#6 04 Aug 2016 18:44

Aacini
Member
Registered: 05 Dec 2012
Posts: 118

Re: windows batch rename folder with the old name stripping out character

for /F "tokens=1-3 delims=-" %%a in ('dir /A:D /B abc-cde-*') do ren "%%a-%%b-%%c" "%%c"

This line rename all folders with a name like "abc-cde-*" into the third dash-separated part of its name.

Offline

#7 04 Aug 2016 18:52

Ehbraheem
New Member
Registered: 04 Aug 2016
Posts: 4

Re: windows batch rename folder with the old name stripping out character

wow  big_smile  It works. Please Explain or point me to somewhere I can learn about the for loop yntax with the tokens and delim. Thanks

Offline

#8 04 Aug 2016 20:43

Aacini
Member
Registered: 05 Dec 2012
Posts: 118

Re: windows batch rename folder with the old name stripping out character

At the command prompt, type: FOR /?

You may also consult the FOR command description in this site: https://ss64.com/nt/for_cmd.html
or search the web for the vast amount of related questions and answers...

Offline

Board footer

Powered by FluxBB