Solved Rename .csv Files based on its content

November 13, 2015 at 02:35:44
Specs: Windows 64, i7
Hi community!

is it possible to rename all *.csv files in a directory with content from the file itself?

Here is an example of one File:

TKNR;Zst;Land;Strklas;Strnum
1830;1105;1;A;1
1830;1105;1;B;2
....
....

I want to get the Second value of the second Line (1105) and append it to the filename. "Zst" is in every line the same in one file.

export-345.csv --> export-345-zst1105.csv
export-345.csv --> export-345-zst3452.csv
....

I don't have much batch-scripting know-how, is it possible?

Thanks!


See More: Rename .csv Files based on its content

Report •

#1
November 13, 2015 at 05:57:48
✔ Best Answer
@echo off
for %%i in (*.csv) do call :REN "%%i"
del *.csv
ren *.new *.csv
goto :EOF

:REN
for /F "skip=1 tokens=2 delims=;" %%j in ('type "%~1"') do (
  copy "%~1" "%~n1-zst%%j.new" > nul & goto :EOF)


Report •
Related Solutions


Ask Question