Windows CMD: Add Suffix to all files in folder
Solution 1:
As others told, it lies in the way ren
interprets wildcards, that's why it can't find files that contains dots *.*
in second command, because:
- You not only removed file extension using first command, but also dots before the extensions:
Artikelnummer.cs > Artikelnummer
- And your second command is looking for filenames containing
.
(which there's none!):
ren *.*
- Also consider
ren
uses*
to refer to file name, so when you look for*.*
(any name, any extension) you're using*
to refer to filename and extension at the same time, which is confusing toren
command!
So, the conclusion is, the only problem was *.*
, replace it with *
:
ren *.cs *.DO.cs
ren * *DO.cs
However, if you want to rename by running a single line of code:
From a command prompt run:
for /f "tokens=* delims=" %a in ('dir /b "%FilesLocation%"') do if %~xa EQU .cs ren "%a" "%~naDO.cs"
Or save and run this script:
@echo off
for /f "tokens=* delims=" %%a in ('dir /b "%FilesLocation%"') do if %%~xa EQU .cs ren "%%a" "%%~naDO.cs"
And don't forget to change %FilesLocation%
with it's real value.
Solution 2:
I was looking for a way to add suffix "_t" to my images.
Just one simple PowerShell command did it !
CD "target folder path here"
Dir | Rename-Item -NewName { $_.basename + "_Suffix” + $_.extension}