回答:
ren同じ長さのテキストでのみテキストを置き換えることができます。たとえば、ファイルfile1.txtとがある場合は、期待どおりfile2.txtにren file*.txt blah*.txt動作します(ファイルblah1.txtとがありますblah2.txt)。ただし、ren blah*.txt myfile*.txtコマンドbombs outを入力すると、名前blah1.txtがmyfile.txt(ではなくmyfile1.txt)に変更さblah2.txtれmyfile.txt、そのファイルがすでに存在するためにに名前を変更できません。
私には2つの解決策があります:
すべてのファイルは同じフォルダにあります
そのフォルダーのコマンドプロンプトから次のコマンドを実行します。
for /f "delims=¯" %i in ('dir /b /on') do ren "%i" "._%i"
サブフォルダにファイルがあり、最初の「n」文字を必要な文字列に置き換えたい場合の完全なソリューション:D
path:""ファイルのルートパス内に配置します(例: "C:\ documents and settings \ user \ desktop \ new folder")numfirstchars2replace:最初の文字を置き換える数字を入れます(あなたの場合、2)str2put:新しいファイル名のプレフィックスとして追加する文字列を入れます(あなたの場合、._)@echo off
::only to tell user what this bat are doing
echo.1.initializing...
::enable that thing to allow, for example, incremental counter in a for loop :)
echo.- EnableDelayedExpansion
SETLOCAL EnableDelayedExpansion
::variables
echo.- variables
:: - place here the absolute root path of your files
set path="put here where are the root folder of your files"
set pathbak=%cd%
set numfirstchars2replace=2
set str2put=._
::go to %path% and its driveletter
echo.- entering the path you want
for /f "delims=¯" %%i in ('echo.%path%') do %%~di
cd %path%
::search all subfolders and save them to a temp file
echo.- searching for subfolders
echo.%path%>%temp%\tmpvar.txt
for /f "delims=¯" %%i in ('dir /s /b /on /ad') do echo."%%i">>%temp%\tmpvar.txt
::execute command for root folder and all found subfolders
echo.
echo.2.executing...
for /f "delims=¯" %%i in (%temp%\tmpvar.txt) do (
cd %%i
echo.- in folder: %%i
for /f "delims=¯" %%j in ('dir /b /on /a-d') do (
set newname=%%j
set newname=!newname:~%numfirstchars2replace%,1000!
echo.- renaming from "%%j" to "%str2put%!newname!"...
ren "%%j" "%str2put%!newname!"
)
)
echo.
echo.3.exiting...
::return to %pathbak% and its driveletter
for /f "delims=¯" %%i in ('echo.%pathbak%') do %%~di
cd %pathbak%
@echo on
Powershell(Windows 7にプリインストールされています)を試してください:
Get-Childitem /path/to/your/files | foreach-object { move-item $_ $("._" + $_.name) }
(私のダウンロードディレクトリでテストしました。)
編集:Siim Kのコードは、すべての「._filename.jpg」に「.jpg」を追加します。Siim Kのコードの最後の ".jpg"を削除すると、ファイルの名前を変更する短くてエレガントなコードができます。
Total Commanderには、非常に優れたマルチ名前変更ツールがあります。
私は、Flash Renamerがバッチでファイルの名前を変更するための優れたツールであることに気づきました。
試用版と完全版($ 20)があり、メタデータに基づいてファイルの名前を変更できます。これは、私が主に使用しているMP3ファイルの名前を変更するのに非常に役立ちます。
ユーザーフレンドリーな方法で一括で名前を変更する方法を探している場合、無料のツールAnt Renamerを試すことができます。実行できるアクションの膨大なリストがあり、名前を変更する前に便利なプレビューが表示されます。音楽、写真、ビデオライブラリをいじるときによく使用します。
私はこのフリーウェアのFile Renamerプログラムを使用して素晴らしい結果を得ました。多くの異なるフィルターとオプションに加えて、結果をテストする機能を提供します。少し時代遅れのUIはおそらくチャンピオンのように機能します。