본문 바로가기
Batch file

파일을 확장명에 따라서 이동하는 Batch File

by treeCoder 2020. 11. 30.

파일을 정리하고 싶은 데, 잘 되지 않는 경우가 있다.

 

@echo off
for %%G in (*.*) do (
    call :sub1 "%%G" %%~xG
)

pause
goto :eof

:sub1
Rem *****  whole file name enclose in double quotation
set a1=%1

Rem *****  get extension name like .bat
set a2=%2

Rem *****  take first char which is '.' out
set b=%a2:~1%

Rem ***************************************************
Rem *****  if not this bat file, move it to a folder 
Rem *****  for example move a.txt to txt folder
Rem *****              move b.exe to exe folder
Rem *****              move c.mp3 to mp3 folder
Rem ***************************************************

if [%a1%] neq ["%~n0%~x0"] (

  if not exist %b%  md %b%  
  move %a1% %b%
)
goto :eof

 

rem https://green-tree-program.tistory.com/9

 

 

파일을 확장명에 따라서 이동하는 Batch File

파일을 정리하고 싶은 데, 잘 되지 않는 경우가 있다. @echo off for %%G in (*.*) do (     call :sub1 "%%G" %%~xG ) pause goto :eof :sub1 Rem *****  whole file name enclose in doub..

green-tree-program.tistory.com

 

댓글