简体   繁体   English

cmd命令转到打开批处理文件的子目录

[英]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.

相关问题 Windows批处理:在由一个称为“批处理”的cmd窗口中运行命令? - Windows Batch: Run command in cmd window opened by a called batch? 使用命令提示符调用子目录中的批处理文件 - Using Command Prompt To Call a Batch File in a Sub-Directory 如何设置目录并在批处理文件中执行命令? - How to set a go to a directory and execute a command in a batch file? CMD命令未在批处理文件中运行 - CMD command not running in batch file 在命令提示符下使用 DEL 批处理文件命令删除后文件 go 在哪里? - Where does the file go after deleting using DEL batch file command in the command prompt? 将system32中的批处理文件目录更改为CMD命令执行点 - Change batch file directory in system32 to CMD command execution point 使用批处理文件自动启动 5 个单独的 cmd 提示,其中每个 cmd 提示指向不同的目录并启动 php172567A5EC93E06Z2567A5EC93E05 - Use a batch file to automatically start 5 separate cmd prompts, where each cmd prompt points to a different directory and starting the php web server 从cmd运行命令,但不在批处理文件中运行 - command is run from cmd but not in batch file Windows 批处理 cmd 文件“标题”命令不起作用 - Windows batch cmd file "title" command not working 如何使用批处理从Windows命令行中的每个子目录返回最新文件 - How to return the newest file from each sub-directory in Windows command line using batch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM