2017-11-24 10 views
0

バッチを使用して複数のファイルの拡張子の名前を一度に変更しようとしています。 しかし私は正しい方向に進んでいるとは確信していません。私はバッチスクリプトを学んでいます。拡張機能の名前をバッチで変更する

例ABCDEFRGGT.word.docx - > ABCDEFRGGT.docx

私はこれまでのところ、これを試してみましたが、それは動作しません。

cd /d C:\Users\XXXX\Documents\rename 
ren '*.word.docx' *.docx 
+0

ないソリューション、しかし:取り替える ' '' "'によって ' – aschipfl

+1

! [Windowsバッチスクリプトを使用してディレクトリ内のすべてのファイルの名前を変更する]の可能な複製(https://stackoverflow.com/questions/9383032/rename-all-files-in-a-directory-with-a-windows-batch-script) ) – MatSnow

+2

コメントとして:あなたは_not_ "拡張子の名前を変更する"です。ファイルはrenaの後に同じ拡張子を持ちますmed: '.docx' – Aacini

答えて

1

このように、ファイル名の拡張子をオフに分割するfor loop、その変数参照~修飾子を使用します。

for %%I in ("%USERPROFILE%\Documents\rename\*.word.docx") do (
    rem // `%%~nI` returns the file name with the (last) extension removed: 
    for %%J in ("%%~nI") do (
     rem /* `%%~nJ` returns the file name with the next-to-last extension removed too; 
     rem `%%~xI` returns the original (last) file name extension: */ 
     ren "%%~I" "%%~nJ%%~xI" 
    ) 
) 
+1

@ user3758867の場合、最初の括弧内に' cd'コマンドを含める必要はありません。ここでは、単一のバッチファイルラインとして、 'For %% I In("%UserProfile%\ Documents \ rename \ *。word.docx ")に対して実行します。%% J In(" %%〜nI ")Do Ren" %%〜I "" %%〜nJ %%〜xI "'。 – Compo

関連する問題