2012-08-28 122 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\ 

注意:我不想用光盘在得到的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%\ .. \资源正是我想要的。 谢谢。 – Leona

0

您是否试过../(或Windows的..\)? 例如:echo The icon.png is located at "..\Resource\"

+0

您应该添加一些背景到您的回答,仅此信息是没有用的,你会被标记为答案,较高的机会,如果你包括至少一个样本。 – Serdalis

1

改变父diretory可以使用

cd .. 

,所以如果你是在“To_delete”你的命令需要像这样

cd ..\Resource 

进入Resource文件夹

+0

谢谢你的回答,但正如我之前提到的,我不想做一个CD。 – Leona

+0

我只是认为这会帮助你改变你的代码,以便你知道如何通过父目录进入资源;) –

1

你可以用FOR循环和文件修饰符~f来解决它。
也看FOR /?

for %%a in ("%CD%\..\resources") do set resourceDir=%%~fa 
echo The icon.png is located at "%resourceDir%" 
相关问题