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

发布于 2025-01-08 08:28:21 字数 418 浏览 1 评论 0原文

所以这个标题很混乱。让我告诉你我的需求: 我想打开一个位于 c:\documents\test\ 的批处理文件,

在此批处理文件中我想收集 c:\documents\test\data 中的名称并转换它到一个文本文件。

现在,执行此操作的简单方法是:

CD c:\documents\test\data
dir/b/o:n > names.txt

但我的问题是我想移动文件夹“\test”,并且始终能够调用“\data”文件中的名称。

因此,这就是我真正需要的:

CD [variable that says current location] + "\data"

但我不知道该怎么做。请解释你的答案谢谢。

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\

in this batch file i'm wanting to collect the names in c:\documents\test\data and convert it to a text file.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如日中天 2025-01-15 08:28:21

%~dp0 是批处理文件的位置(运行 FOR /? 了解更多信息)

%~dp0 is the location of the batch file (Run FOR /? for more info)

慕烟庭风 2025-01-15 08:28:21

这 。字符代表当前工作目录...是否

cd .\data

满足您的需要?

编辑:

所以我看到没有人真正回答你的问题。根据您当前的编辑,您需要定义一个 Windows 环境变量来保存数据文件夹所在位置的路径,并且当您移动文件夹时,该过程的一部分需要更新环境变量,以便批处理脚本可以正确找到它。

因此,如果您将数据文件夹移动到 C:\archive\test\data 您将需要一些过程来调用命令行,

SET BATCH_ARCHIVE_PATH="C:\archive\test"

然后在批处理脚本中您将执行以下操作:

CD "%BATCH_ARCHIVE_PATH%\data"
dir/b/o:n > names.txt

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.

so if you moved your data folder to C:\archive\test\data you would need some process to call the command line with

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文