古いファイル(主にpdfsですが、いくつかの.docまたは.docx)があります。その内容は日付が追加されています。末尾のファイル名の末尾に(dd.mm.yyyy)をプレフィックス(yyyy-mm-dd)に改名します。
銀行不要な支払い2007年4月10日
銀行その他のトピック2007年4月11日
論文2007年4月10日
私は内のすべてのファイルの名前を変更バルクにしたいを追加するには何もありません名前を変更する特定のフォルダ
銀行u 2007年4月10日 2007-10-04 に銀行不要な支払いnneeded支払い
私はすでに直接任意のフォルダにそれを活性化させることができるように私のSendToフォルダにあるバッチファイルを持っており、それは、すでに各地反復するために取り組んでいますファイル。それはファイル名をトークンに壊して、それらを私に示すことさえできます。
チェックを(それが有効であるかどう任意のチェックなし!)現在のトークンが(%% a)のDD.MM.YYYY形式の日付である場合:私は単に働いて得ることはありません何
。日付が見つかった場合は、新しい文字列(yyyy-mm-dd)を作成し、他のすべてのトークンを使用して新しいファイル名を作成し、現在のファイルの名前を変更する必要があります。
あなたはこれで私を助けることができますように!
現在のコード:
@ECHO OFF
setlocal enabledelayedexpansion
rem *******************************
rem this is used to get the path of the currently used folder.
(set foldername=%1)
rem this overwrites the foldername with the "%~dp1 - expands %1 to a drive letter and path only"
call set foldername=%%~dp1
rem now we have to check how many files we find in our folder
for /F "usebackq delims=" %%i in (`dir /a:-d /b "%%foldername%%\*.*"`) do set /a dirCnt+=1
rem this version works for folders without spaces (C:\scripttest) (no "")
rem for /F "usebackq delims=" %%i in (`dir /a:-d /b %%foldername%%\*.*`) do set /a dirCnt+=1
rem when we don't find any files with the old date format in the folder, we will abort the batch
IF (%dirCnt%) EQU (0) (
echo No files found in folder "%foldername%". Exiting.
pause
EXIT 1
)
echo Found %dirCnt% files in folder "%foldername%".
rem now we start to finally do stuff!
set tmpCnt=0
set tmp2Cnt=0
rem we will go over each FILE here
for /F "usebackq delims=" %%i in (`dir /a:-d /b "%foldername%\*.*"`) do (
set /a tmpCnt+=1
call echo Proceed file %%tmpCnt%% from %%dirCnt%%: %%i.
rem here we need to find IF there is a date in format dd.mm.yyyy available
rem here we go over each PART of that file, automatically split by " " removing the ending (~n)
for %%a in (%%~ni) do (
rem SET "var="&for /f "tokens=1 delims=" %%i in ("%%a") do set var=%%i
rem if defined var (echo %%a is NOT numeric) else (echo %%a is numeric)
echo %%a
)
rem this echos only the file extension including the . = ".doc" or ".pdf"
echo %%~xi
rem echo %%a
rem IF NOT, jump to next file!
rem we copy the dd, mm and yyyy to different variables
rem we build a new variable with yyyy-mm-dd
rem we remove the old date format (dd.mm.yyyy) and add the new date format (yyyy-mm-dd) to the file as prefix
rem if this worked, we add 1 to the count!
set /a tmp2Cnt+=1
)
rem set "filename=%%~nf"
rem ren "%%f" "!filename:~0,-4!%%~xf"
rem for /f "delims=" %%i in ('dir /b /a-d *.txt') do ren "%%~i" "%%~ni 1.1%%~xi"
call echo process finished without errors - %%tmp2Cnt%% from %%dirCnt%% files processed, check folders for results!
pause
こんにちは! ありがとうございました!それは魅力のように働いた! sendmeフォルダ内で使用できるように少し変更しましたが、送信したコードを変更せずにすごくうまくいきます!すべてのファイルがチェックされます。有効な日付がある場合、日付は改訂され、名前が変更されます。 ありがとうございました。 また、私はそれほど多くの文字を使用することはありませんでした! – mschmidt
あなたの質問タイトルを編集して、より少ない言葉にする;-) – LotPings