0

I have 16 folders like:

Sample-2.1-1 Sample-2.2-1 Sample-2.3-1 ..... Sample-2.16-1 

Those are inside a folder SVN for example

D:\SVN\Sample-2.1-1 D:\SVN\Sample-2.2-1 D:\SVN\Sample-2.3-1 ..... D:\SVN\Sample-2.16-1 

Now I want to rename all these 16 folders by removing Sample- in their names such as:

2.1-1 2.2-1 2.3-1 ..... 2.16-1 

How could I do it using for command inside .

6
  • Please try something and let us know what happens. We aren't here to write the code for you. Consider looking up for /f command using delims=-. Commented Nov 13, 2019 at 18:53
  • I tried something like set dirname="D:\SVN" && for /d "tokens=1,2 delims=- "%%G in ('dir /b %dirname%') do rename %dirname%\%%G-%%H %%H where %%G is the string before delimiter and %%H is string after delimiter. But it gives me error like " in was unexpected at this time." . Commented Nov 13, 2019 at 21:25
  • You need for /f, not for /d. Also put a space between the double quote and %%G. Commented Nov 13, 2019 at 21:39
  • with command set dirname=D:\SVN && for /f "tokens=1,2 delims=-" %G in (' dir /b %dirname%') do rename %dirname%\%G-%H-1 %H-1 i get rename D:\SVN \Sample-2.2-1 2.2-1 on the cmd. It means i get a space between rename D:\SVN and \Sample-2.2-1 instead of rename D:\SVN \Sample-2.2-1 2.2-1 i get rename D:\SVN \Sample-2.2-1 2.2-1. If cmd is able to get command without space everything would be fine i guess Commented Nov 13, 2019 at 22:08
  • ren "%dirname%\%G-%H" "%H" Commented Nov 13, 2019 at 22:12

1 Answer 1

1
pushd "d:\svn" for /f "tokens=1*" %%A in ('dir /b /ad sample-*') do ren "%%A-%%B" "%%B" popd 

Or, in the off chance that you have a folder name like sample--xxxx, then

pushd "d:\svn" for /d %%F in (sample-*) do for /f "tokens=1*" %%A in ("%%F") do ren "%%F" "%%B" popd 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.