我有5000个 .pdf
文件,我必须重命名并移动到新创建的文件夹中,这些文件夹的名称基于原始文件名。
例如:原始名称是 crf - aaa - 208912--2089120010
。
文件夹名称应为 208912
,文件名 2089120010
。
请帮助完成此过程。
&#xA ;答案 0 :(得分:0)
您可能需要使用以下代码段:
rem // Change to directory containing the files:
pushd "D:\Data" && (
rem // Retrieve matching files and iterate through them:
for /F "delims=" %%F in ('dir /B /A:-D "*--*--*--*.pdf"') do (
rem // Store name of currently iterated file:
set "NAME=%%F"
setlocal EnableDelayedExpansion
rem /* Split name into tokens separated by `--`; since `for /F` uses characters
rem as delimiters but not strings, `--` is replaced by `|` intermittently: */
for /F "tokens=3* delims=|" %%I in ("!NAME:--=|!") do (
endlocal
rem // Create sub-directory:
mkdir "%%I"
rem // Rename and move file:
move "%%F" "%%I\%%J"
)
endlocal
)
rem // Restore previous working directory:
popd
)