2012-12-02 4 views
1

아래 코드는 파일에서 파일 확장명을 제거합니다. 그러나 나는 그것이 어떻게하는지 이해할 수 없다. 현재 디렉토리에있는 모든 파일을 단순한 형식으로 나열합니다. 그러나 그 후에 나는 일종의 길을 잃었습니다. 누군가 나를 도울 수 있겠습니까?이 특정 배치 스크립트는 어떻게 작동합니까?

@echo off 
cd %1 
if exist filelisting.txt del filelisting.txt 
for /F "delims=" %%j in ('dir /A-D /B /O:GEN') do echo %%~nj >> filelisting.txt 

답변

1

첫 번째 파일은 파일 이름 다음 확장으로 분류되어 있습니다 및 폴더 /O:GEN으로 (중복입니다) 함께 그룹화됩니다. /B 전체 경로는 제외되며 /A-D 폴더는 제외됩니다.

  1. DIR
  2. FOR /F
  3. FILE ATTRIBUTES
: FOR /F %%J IN ('command') DO (..)으로 명령 출력의 모든 라인은 일부 링크는 %%~nJ가 extension.Here없이 파일 이름 만 촬영으로 %%J variable.And에있는 설정

편집 : 예 :

@echo off 
echo %~0 - expands %i removing any surrounding quotes (") 
echo %~f0 - expands %i to a fully qualified path name 
echo %~d0 - expands %i to a drive letter only 
echo %~p0 - expands %i to a path only 
echo %~n0 - expands %i to a file name only 
echo %~x0 - expands %i to a file extension only 
echo %~s0 - expanded path contains short names only 
echo %~a0 - expands %i to file attributes of file 
echo %~t0 - expands %i to date/time of file 
echo %~z0 - expands %i to size of file 
echo %~$PATH:0 - searches the directories listed in the PATH environment variable and expands %i to the fully qualified name of the first one found. 
echo %~dp0 - expands %i to a drive letter and path only 
echo %~nx0 - expands %i to a file name and extension only 
echo %~fs0 - expands %i to a full path name with short names only 
echo %~dp$PATH:0 - searches the directories listed in the PATH environment variable for %i and expands to the drive letter and path of the first one found. 
echo %~ftza0 - expands %i to a DIR like output line 
pause 

이 파일을 .bat 파일로 저장하십시오. % 0은 .bat 파일이라고하는 경로입니다.이 파일은 모든 % ~ 0 작업을 나열합니다. %~은 일괄 파일 인수 % 0, % 1 .. 또는 FOR 변수에서만 한쪽 끝에서 작동합니다.

+0

%% ~ nJ는 어떻게 작동합니까? ~ n은 무엇을합니까? – user1667307

+0

변수가 파일 인 경우 한쪽 묶음 변수 (% 0, % 1 ... 또는 FOR 루프의 변수)의 확장자가없는 파일 이름이 필요합니다. 두 번째 또는 세 번째 링크를 참조하십시오 – npocmaka

+0

수정 된 답변을 확인하십시오. – npocmaka