"."를 대체할 배치 파일 와 함께 "-"

"."를 대체할 배치 파일 와 함께 "-"

파일 확장자를 유지해야 하며 하위 폴더를 통해 작업해야 합니다.

예: "File.name.ext"는 "File-name.ext"가 되어야 합니다.

나는 쉘 스크립트에 대해 전혀 무지하므로 답변에 자세히 설명해주세요. 스위치가 무엇을 의미하는지 또는 해당 문제에 대한 경로를 지정하는 방법조차 모릅니다.

답변1

나는 실제로 다른 답변에 전적으로 동의합니다. GUI 대량 이름 바꾸기 유틸리티는 다음과 같습니다.그래서사용하기가 훨씬 쉽습니다. 그러나 재미를 위해 현재 디렉터리에 있는 모든 파일의 이름을 재귀적으로 바꿔야 하는 다음 배치 파일을 작성했습니다. 그리고 하위 디렉토리. 그리고 교체하십시오. -(예를 들어 "긴 .file. .name.ext" 될 것입니다 "긴 -file- -name.ext"):

@echo off
setlocal enabledelayedexpansion
for /r %%f in (*.*) do (
    set fn=%%~nf

    REM Remove the echo from the following line to perform the actual renaming!
    if not [!fn!]==[] if not ["%%~nxf"]==["!fn:.=-!%%~xf"] echo ren "%%~f" "!fn:.=-!%%~xf"
)
pause

배치 파일을 한 번 실행한 후 출력이 만족스러우면 단어 echo(첫 번째 줄이 아닌 두 번째 인스턴스)를 제거하고 파일을 다시 실행하여 실제 이름 바꾸기를 수행합니다.

답변2

그렇다면 왜 배치 파일을 사용하고 싶은지 이해하지 못합니다. 다음과 같은 수많은 GUI 이름 바꾸기 도구 중 하나를 사용해 보는 것이 어떻겠습니까?

http://www.beroux.com/english/softwares/renameit/

특정 보트가 보트를 띄우지 않는 경우 다음 퍼레이드를 확인하세요.

http://www.techsupportalert.com/best-free-name-utility.htm

답변3

원하는 작업을 수행할 수 있는 최종 테스트 버전의 배치 파일은 다음과 같습니다. 파일 이름이나 확장자가 있거나 없는 파일에서 작동하지만 파일 이름이 포함되거나 확장자가 있는 %파일 !문제를 야기하다.

지연된 확장을 사용하므로 지연된 확장을 켠 상태에서 명령 프롬프트에서 실행해야 합니다. (간단히 실행해도 setlocal /enabledelayedexpansion토글만 되기 때문에 잘리지 않습니다.)이미 활성화된 경우; 명령 프롬프트가 실행될 때 활성화되지 않으면 아무 효과가 없습니다.)

스위치로 명령 프롬프트를 열어 지연 확장을 켤 수 있지만 /V:ON아래 배치 파일과 같이 기존 명령 프롬프트에서 그렇게 할 수도 있습니다.

@echo off

:: This batch file (prints the command to) rename files so that
:: any dots (.) are replaced with dashes (-)
::
:: Note, files with names containing percents (%) and exclamantions (!)
:: will intefere with command-prompt syntax and are not supported, but
:: can be worked around: https://stackoverflow.com/questions/5226793/

:: If this batch-file has no parameters...
if [%1]==[] (
    :: Open a new command-prompt with delayed-expansion enabled and call self
    cmd /v:on /c "%0" +
    :: Quit
    goto :eof
)

:: Recurse through all files in all subdirectories
for /r %%i in (*) do (

    rem (:: cannot be used for comments in a FOR loop)
    rem Check if it has an extension
    if [%%~xi]==[] (
        rem If it has an extension, preserve it
        set RENFN=%%~nxi
    ) else (
        rem Copy the path (and filename)
        set RENFN=%%~ni
        rem Check if it has a filename
        if not [%%~ni]==[] (
            rem If it has a filename, replace dots with dashes
            set RENFN=!RENFN:.=-!
        )
    )

    rem Rename original file
    ren "%%i" "!RENFN!%%~xi"

)

:: Exit spawned shell (no need to use setlocal to wipe out the envvar)
exit

:: Test output:
::
:: C:\t> dir /b/a
::
:: .txt
:: blah
:: file.blah.txt
:: foo.bar.txt
:: super duper. .blah.ttt. omergerd.---.mp4
:: t.bat
::
:: C:\t> t.bat
::
:: ren "C:\t\.txt" ".txt"
:: ren "C:\t\blah" "blah"
:: ren "C:\t\file.blah.txt" "file-blah.txt"
:: ren "C:\t\foo.bar.txt" "foo-bar.txt"
:: ren "C:\t\super duper. .blah.ttt. omergerd.---.mp4" "super duper- -blah-ttt- omergerd----.mp4"
:: ren "C:\t\t.bat" "t.bat"

관련 정보