重命名pdf文件并创建和移动文件基础文件名

时间:2017-04-24 08:21:57

标签: pdf cmd

我有5000个 .pdf 文件,我必须重命名并移动到新创建的文件夹中,这些文件夹的名称基于原始文件名。


&#xA ;

例如:原始名称是 crf - aaa - 208912--2089120010





文件夹名称应为 208912 ,文件名 2089120010





请帮助完成此过程。

&#xA ;

1 个答案:

答案 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
)
相关问题