2017-11-17 14 views
1
나는 아래와 같은 파일에서 특정 문자를 제거 할 폴더 및 하위 폴더에있는 파일의 집합 데

:파일 확장명 앞에 특정 문자를 제거하여 파일 이름을 일괄 적으로 바꿉니 까?

adjust_the_m.2_retainer_zh-cn.dita 
assert_physical_presence_en-us.dita 
back_up_the_server_configuration_es.dita 
backplane_cable_routing_fr-fr.dita 

을 나는 다음과 같이 그 이름을 바꾸려면 :

adjust_the_m.2_retainer.dita 
assert_physical_presence.dita 
back_up_the_server_configuration.dita 
backplane_cable_routing.dita 

I을 이 명령 프롬프트 Batch.bat 파일에 있습니다.

+0

이 이름 (또는 형식)을 가진 다른 파일의 모든 하위 디렉토리를 검사하려면 배치 스크립트가 필요합니까? 아니면 파일을 목록으로 가져 와서 이름을 바꿔야합니까? – cowCrazy

+0

디렉터리 및 하위 디렉터리의 파일 이름을 변경할 수있는 배치 스크립트가 필요합니다. 다른 파일도 될 수 있습니다 adjust_the_m.2_retainer_zh-cn.dita assert_physical_presence_en-us.ditamap back_up_the_server_configuration_es.dita이 backplane_cable_routing_fr-fr.ditaval – Maxim

답변

0

이제 마지막 코드는 다음과 같습니다 확장자를 추가

@echo off 
setlocal enabledelayedexpansion 
for /r %%a in (*.dita *.ditamap *.ditaval) do call :process "%%~dpna" "%%~xa" 
goto :eof 

:process 
set "file=%~1" 
for %%b in (%file:_= %) do set last=_%%b 
rem echo %last% 
set "file=!file:%last%=!" 
move "%~1%~2" "%file%%~2" 
echo %file%%~2 

@Stephan에게 감사드립니다.

1

파일 이름의 마지막 부분 (_으로 구분됨)을 제거 하시겠습니까?
, 마지막 부분을 얻을, 확장 (%%~dpna)없이 이름을 가지고 파일 이름 (set 변수 문자열 교체)에서 분리 (%%~xa)

@echo off 

setlocal enabledelayedexpansion 
for /r %%a in (*.dita) do call :process "%%~dpna" "%%~xa" 
goto :eof 

:process 
set "file=%~1" 
for %%b in (%file:_= %) do set last=_%%b 
set "file=!file:%last%=!" 
move "%~1%~2" "%file%%~2" 
+0

감사하지만,이 일을하지 않았다! 위의 명령을 사용하여 이름이 바뀌지 않았습니다. – Maxim

+0

의 이름을 바꾸려면 ren과 같이 [ren] (https://ss64.com/nt/ren.html) 명령을 사용하십시오. %% a ""% file %% ~ 2 "'주의 : 이미 이름을 바꾼 경우 파일 이름을 제거하면 이름의 다른 부분이 제거됩니다 (예 :'adjust_the_m.2_retainer.dita' ->'adjust_the_m.2.dita' – Stephan

+0

).하지만 이것도 작동하지 않습니다! – Maxim