[英]cmd command to go to a sub directory of where the batch file was opened
So that title was confusing. 这样的标题令人困惑。 Let me tell you my needs: I'm wanting to open a batch file that is located in
c:\\documents\\test\\
让我告诉你我的需求:我想打开一个位于
c:\\documents\\test\\
的批处理文件
in this batch file i'm wanting to collect the names in c:\\documents\\test\\data and convert it to a text file. 在这个批处理文件中,我想收集c:\\ documents \\ test \\ data中的名称并将其转换为文本文件。
Now the easy way to do this would be: 现在,简单的方法是:
CD c:\documents\test\data
dir/b/o:n > names.txt
but my issue is that i want to move the folder "\\test" around and always be able to call on the names in the "\\data" file. 但我的问题是,我想移动文件夹“\\ test”,并始终能够调用“\\ data”文件中的名称。
Therefore this is what i really need: 因此,这就是我真正需要的:
CD [variable that says current location] + "\data"
but i dont know how to do this. 但我不知道该怎么做。 Please explain your answers thanks.
请解释您的答案谢谢。
%~dp0
是批处理文件的位置(运行FOR /?
了解更多信息)
the . 的。 character represents the current working directory... does
字符代表当前的工作目录...
cd .\data
do what you need? 你需要什么?
edit: 编辑:
So I see no one really answered your issue. 所以我看到没有人真正回答你的问题。 Based on your current edit you would want to define a windows environment variable that held the path to wherever your data folder is, and when you move the folder part of that process would need to update the environment variable so your batch script can find it appropriately.
根据您当前的编辑,您将需要定义一个Windows环境变量,该变量将路径保存到数据文件夹所在的位置,并且当您移动文件夹时,该过程的一部分将需要更新环境变量,以便您的批处理脚本可以适当地找到它。 。
so if you moved your data folder to C:\\archive\\test\\data you would need some process to call the command line with 因此,如果您将数据文件夹移动到C:\\ archive \\ test \\ data,则需要一些进程来调用命令行
SET BATCH_ARCHIVE_PATH="C:\archive\test"
then in your batch script you would do something like: 然后在您的批处理脚本中,您将执行以下操作:
CD "%BATCH_ARCHIVE_PATH%\data"
dir/b/o:n > names.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.