2017-04-24 137 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 
)