2012-08-28 4 views
1

지옥 모두, 나는 같은 배치 파일이 배치 파일의 안돼서 :배치 파일 | 상위 디렉토리

@ECHO OFF 
if not exist To_delete mkdir To_delete 
if not exist resources mkdir resources 
copy "C:\icon.png" "resources" 

cd /d To_delete 
echo The current folder is : "%CD%" 
echo The icon.png is located at "CODE_I_NEED_IS_HERE" 

The result should be: 
The current folder is : C:\Users\Leona\Desktop\To_delete\ 
The icon.png is located at C:\Users\Leona\Desktop\Resource\ 

주의 : 그에서 CD로 icon.png의 길을받지 않으 폴더, 내가 원하는 것은 현재 폴더가 "To_delete"일 때 리소스 폴더 내의 파일을 검색하는 것입니다.

고맙습니다.

답변

2
@ECHO OFF 
if not exist To_delete mkdir To_delete 
if not exist resources mkdir resources 
copy "C:\Documents and Settings\mlastg\Desktop\logo.png" "resources" 

cd /d To_delete 
echo The current folder is : "%CD%" 
dir /s/b/A:-D "%CD%\..\resources" 

마지막 명령에 또 봐. 이제 당신은 혼자이 정보가 유용하지 않습니다, 당신의 대답에 약간의 컨텍스트를 추가해야합니다 당신의 대답을

C:\Documents and Settings\mlastg\Desktop>batch.bat 
     1 file(s) copied. 
The current folder is : "C:\Documents and Settings\mlastg\Desktop\To_delete" 
C:\Documents and Settings\mlastg\Desktop\resources\logo.png 
+0

dir/s/b/A : -D "% CD % \ .. \ resources"는 다음과 같습니다. 내가 원하는 것은 아니지만 % CD % \ .. \ resources가 내가 원하는 것입니다. 감사합니다. – Leona

0

../ (또는 Windows의 경우 ..\)을 사용해 보셨습니까? 예를 들어 : 당신은 당신이 "To_delete"에 그렇다면

cd .. 

을 사용할 수 있습니다 diretory echo The icon.png is located at "..\Resource\"

+0

를 얻기 위해 정교하게 할 수 있습니다 적어도 하나 개의 샘플을 포함하는 경우, 당신은 대답으로 표시되는 더 높은 기회를 가질 것입니다. – Serdalis

1

부모로 변경하는 당신의 명령에 들어갈이

cd ..\Resource 

같이 할 필요가 리소스 폴더

+0

답장을 보내 주셔서 감사합니다.하지만 전에 memtioned로, 나는 CD를하고 싶지 않아. – Leona

+0

방금이 코드를 변경하면 부모 디렉토리를 통해 리소스에 들어가는 방법을 알 수 있다고 생각했습니다.) –

1

FOR 루프와 파일 수정 자 ~f으로 해결할 수 있습니다.
당신에게 리소스 폴더에있는 모든 파일의 경로를 줄 것이다 FOR /?

for %%a in ("%CD%\..\resources") do set resourceDir=%%~fa 
echo The icon.png is located at "%resourceDir%" 
관련 문제