2015-02-01 2 views
-1

현재 최근에 만든 폴더의 이름을 바꾸려고합니다. REN (또는) RENAME이라는 명령이 있지만 폴더가 아닌 파일의 이름을 바꾸는 데 사용됩니다.배치 스크립트를 사용하여 폴더 이름 바꾸기

Below is the code that i am working to achieve this. 

    for %%# in ("%mask%_*") do (
    if not exist "%destination_dir%\%mask%" mkdir "%destination_dir%\%mask%" 
    move /y "%%~#" "%destination_dir%\%mask%" 
    if exist "%destination_dir%\%mask%" ren "%destination_dir%\%mask%_%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%" 
    ) 

어떻게 구현합니까?

+0

http://www.computerhope.com/renamehl.htm를? 그냥 폴더 이름을 사용하여 작업해야합니다 .... –

+0

나는 구문의 명령이 잘못되었습니다. "% destination_dir % \ % mask %"이름 바꾸기 "% destination_dir % \ % 마스크 % _ % 날짜 : ~ 10,4 %% 날짜 : ~ 7,2 %% 날짜 : ~ 4 , 2 % - % 시간 : ~ 0.2 %% 시간 : ~ 3,2 % " – ihappyk

+0

ren도 폴더를 처리합니다. – Serenity

답변

3

if exist으로 시작하는 배치 코드에서 ren 명령은 1 매개 변수로 시작됩니다. 따라서 폴더/파일의 새 이름이있는 두 번째 매개 변수가 누락되었습니다. 두 번째 매개 변수는 항상 경로가없는 파일/폴더의 새 이름이어야합니다.

귀하의 배치 코드가 가장 가능성이 있어야한다 :

for %%# in ("%mask%_*") do (
    if not exist "%destination_dir%\%mask%" mkdir "%destination_dir%\%mask%" 
    move /y "%%~#" "%destination_dir%\%mask%" 
    if exist "%destination_dir%\%mask%" ren "%destination_dir%\%mask%" "%mask%_%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%" 
) 
관련 문제