I have read all the similar questions and tried to use it to make a batch script, but unsuccessfully.
I have several *txt files, which are containing information within the file, which should be stored in the file name.
E.g. the *txt below, I would like to store the date from the first line (20171115) and the number in the back of the file (905707) in the file name.
In this case, the file name should be "20171115_BOM_905707.txt"
Can anybody help me?
答案 0 :(得分:0)
未经测试。
setlocal enableDelayedExpansion
set "dir_with_files=C:\files"
for %%# in ("%dir_with_files%\*") do (
set "date_="
set "number="
for /f "usebackq skip=1 tokens=3,4,5,6 delims=. " %%a in ("%%#") do (
if not defined date_ (
set "date_=%%a%%b%%c"
set "number=%%d"
)
)
ren "%%~f#" "!date_!_BOM_!number!%%~x#"
)
endlocal