에 파일의 이름을 후행 (dd.mm.yyyy)로 이름을 바꿉니다. 이전 파일 (대부분 pdfs뿐만 아니라 .doc 또는 .docx)이 많이 있습니다. 날짜가 추가 된 콘텐츠접미사 (yyyy-mm-dd)
은행 불필요한 지불 2007년 4월 10일
은행 다른 주제 2007년 4월 11일
논문 2007년 4월 10일
나는 모든 파일의 이름을 변경 대량 원하는을 추가하는 것도 이름을 바꿀 특정 폴더
은행 u nneeded 지불 2007년 4월 10일 이미 수있을 내 SendTo 폴더에 배치 파일을
2007-10-04 은행 불필요한 지불에 직접 폴더를 활성화하고 이미 온통 반복하기 위해 노력하고 있습니다 파일. 파일 이름을 토큰으로 분류하여 표시 할 수도 있습니다.
단순히 작동하지 않는 내용 : 현재 토큰 (%% 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