
Substring in Set command (Refer: !_dir:*- =!) Rem :: or, smaller with the same results.įor /d %i in (*)do cmd/v/c"set "_dir=%~nxi"&move "%~nxi" "!_dir:*- =!"" With for /d all directories will be listed in the loop, and their source names will be in %~nxi, which can be used in the ren command syntax.įor target name, use !_dir:*- =!, it will remove everything ( *) that comes before -, and already defining the destination name by expanding in same line the !_dir! variable without unwanted characters using cmd.exe /v:on /cįor what you have been trying, a use of for /d loop and substring set in ren syntaxes would be resolved by: for /d %i in (*)do cmd.exe /v:on /c "set "_dir=%~nxi" & move "%~nxi" "!_dir:*- =!"" You can do this using a for /d loop and set to remove everything that comes before (and together) the *-: Return the whole folder name use %%I or %%~nxI Name like "Sample 2.6.4" the output of %%~nI will be truncated to "Sample 2.6" to


%~xI - expands %I to a file extension only Use the FOR variable syntax replacement:.%%~nxi => expands %%~i to a file/dir name and extension %~xi - expands %i to a file/dir extension only %~ni - expands %i to a file/dir name only %~i - expands %i removing any surrounding quotes (") %~fi - expands %i to a fully qualified path file/dir name only Using a Forloop you can expand your variable:.

What can and will help in many commands would be to familiarizing yourself with:
