문제

나는 모두에 대한 내 코드 기반을 검색하려고합니다 jscript 디렉토리를 한 다음 다음 배치 스크립트를 사용하여 해당 디렉토리 내에서 상대 파일 목록을 받으십시오 ...

@echo off

setlocal enableextensions enabledelayedexpansion

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S jscripts') DO (
    CD %%G
    CD dev

    SET "currentDir=!cd!"
    IF NOT "!currentDir:~-1!"=="\" SET "currentDir=!currentDir!\"

    FOR /r %%F IN (*.js) DO (
        SET "relativePath=%%F"
        SET "relativePath=!relativePath:%currentDir%=!"

        ECHO !relativePath!
    )
)

그것은 모두가 될 때까지 예상대로 작동합니다 ...

SET "relativePath=!relativePath:%currentDir%=!"

내가 어떤 형식을 작성 해야하는지 알아낼 수 있습니다 ...

c:\dir\jscript\dev\file.js

안으로...

file.js

도와주세요!


추가 정보

디렉토리 설정은 다음과 같습니다

dir
    jscripts
        dev
            file.js
            file2.js
        live
            file.js
            file2.js


dir2
    jscripts
        dev
            file.js
            file2.js
        live
            file.js
            file2.js

나는 모든 것을 찾고 싶다 jscripts 디렉토리, CD, 모든 JS 파일 목록 가져 오기 개발자와 관련이 있습니다 예배 규칙서

도움이 되었습니까?

해결책 2

@echo off
setlocal enableextensions enabledelayedexpansion

rem Where to start
pushd "c:\wherever\global2_root\"

rem Search .....\dev directories
for /f "tokens=*" %%d in ('dir /ad /s /b ^| findstr /e "\\dev"') do (
    rem change to that directory
    pushd "%%~fd"
    echo Now in !cd!
    rem process files inside directory
    for %%f in (*.js) do (
        echo %%f
    )
    rem return to previous directory
    popd
)
rem return to initial directory
popd

rem cleanup 
endlocal

다른 팁

전체 경로 사용이 포함 된 변수에서 파일 이름과 확장을 추출하려면 %~nx0 에서와 같이

set G=c:\dir\jscript\file.js
echo %~nxG

다음을 인용합니다 비슷한 질문에 대한 답변

%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file

The modifiers can be combined to get compound results:
%~dpI       - expands %I to a drive letter and path only
%~nxI       - expands %I to a file name and extension only
%~fsI       - expands %I to a full path name with short names only

이것은 "for /?"의 복사 페이스트입니다. 프롬프트에 명령. 도움이되기를 바랍니다.

관련된

상위 10 개의 DOS 배치 팁 (예, DOS 배치 ...)batchparams.bat (요점으로 소스에 대한 링크) :

C:\Temp>batchparams.bat c:\windows\notepad.exe
%~1     =      c:\windows\notepad.exe
%~f1     =      c:\WINDOWS\NOTEPAD.EXE
%~d1     =      c:
%~p1     =      \WINDOWS\
%~n1     =      NOTEPAD
%~x1     =      .EXE
%~s1     =      c:\WINDOWS\NOTEPAD.EXE
%~a1     =      --a------
%~t1     =      08/25/2005 01:50 AM
%~z1     =      17920
%~$PATHATH:1     =
%~dp1     =      c:\WINDOWS\
%~nx1     =      NOTEPAD.EXE
%~dp$PATH:1     =      c:\WINDOWS\
%~ftza1     =      --a------ 08/25/2005 01:50 AM 17920 c:\WINDOWS\NOTEPAD.EXE
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top