用于使用当前路径位置设置变量的批处理脚本
如何设置当前位置的变量?例如,如果我进入 c:\test
并希望将变量设置为 test
并且如果我进入 c:\test\test2
> 变量将被设置为 test2
。
我正在考虑使用 for
进入很多文件夹并检查某些文件是否存在,如果存在正确的文件我想将当前文件夹设置为变量,以便我可以复制路径并复制该文件夹。
主要问题是将其余文件复制到与 .inf 文件相同的文件夹中。
How can I set a variable with the current location? For instance, if I get in c:\test
and want to set the variable to test
and if I get inside c:\test\test2
the variable will be set to test2
.
I'm thinking about using a for
to get inside a lot of folders and check if some file exists, if the correct file exist I want to set the current folder to a variable so I can copy the path and copy the folder.
The main problem deals with copying the rest of the files is the same folder as the .inf file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当前目录位于“shadow”变量 cd 中。
你可以尝试
The current directory is in the "shadow" variable cd.
You could try
这扩展到驱动器和当前运行的批处理文件的路径。我通常在我的批处理文件中添加以下内容:
编辑:看来我不明白OP。我的示例获取当前运行脚本的位置,而不是“当前目录”。 +1 杰布。
This expands into the drive & path of the currently running batch file. I usually surround my batch files with something like:
Edit: It seems I didn't understand the OP. My example gets the location of the currently running script, not the "Current Directory". +1 to jeb.
我认为这里有点混乱。 %CD% 始终拥有当前目录,因此您无需添加任何内容即可拥有它。但是,通过重读您原来的问题,我认为您需要当前目录的最后一部分,即当前位置的名称,不包括所有以前的位置。如果是这样,那么你可以使用这个:
I think there is a little confussion here. %CD% always have the current directory, so you don't need to add anything to have it. However, by rereading your original question, I think that you need the LAST PART of the current directory, that is, the name of the current location excluding all previous locations. If so, then you may use this: