2017-04-24 9 views
0

名前を変更して元のファイル名に基づいて名前を変更した新しく作成したフォルダに移動する必要があるファイルを持っています。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 
) 
関連する問題