2010-07-05 4 views
1

특정 폴더로 이동하는 데 필요한 파일이 약 250 개 있습니다. 문제는 폴더의 파일 이름이 부분적으로 만 존재한다는 것입니다.부분 이름을 가진 폴더로 파일 이동

예를 들어, 각 폴더가 실제 파일 이름으로 시작될 때 "12345.txt"파일을 "12345 - hello"폴더로 이동해야합니다.

DOS의 배치 파일에서이 작업을 수행 할 수 있습니까?

감사합니다. 윈도우를 가정

+2

* Really * DOS? 거기에 긴 파일 이름은 어디에서 얻었습니까? – Joey

+1

폴더 이름의 예를 들어 '파일 이름 - 무언가'와 같은 규칙 구조가 있습니까? 다음 상황이 가능합니까? 파일 이름 "a.txt", 첫 번째 폴더 "a000", 두 번째 폴더 "a111", 즉 모호 할 수 있습니까? – chalup

답변

3

, 그것은 어려운 사실이 아니다 :

@echo off 
rem loop over all files 
for %%f in (*) do call :process "%%f" 

rem this is necessary to avoid running the subroutine below 
rem after the loop above ended 
goto :eof 

rem subroutine that gets called for every file 
rem this finds the first matching folder and moves the file there 
:process 
rem the /d loops over all directories - the mask ensures that 
rem the directory name starts with the given file name (without 
rem extension) 
for /d %%d in ("%~n1*") do (
    echo Moving "%~1" to "%%d" ... 
    move "%~1" "%%d" 
    rem Return since the file was moved already 
    goto :EOF 
) 

my SVN repository에서 찾을 수 있습니다.

+0

요하네스에 감사드립니다. 그것은 효과가 있었다. 고마워, trully 감사합니다. – user383963

관련 문제