2017-04-24 82 views
0

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

例如:原来的名字是crf--aaa--208912--2089120010

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

请帮助完成此过程。

+0

帮助意味着你做你自己的东西,所以请分享你到目前为止尝试和精确地描述你在哪里卡住了!关于StackOverflow不是免费的代码写作服务! – aschipfl

回答

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 
)