如何从批处理脚本中的字符串中提取文件夹路径
我一直在致力于构建一个打包实用程序,它基本上获取两个 SVN 修订版之间所有添加/修改的文件,然后将它们复制到本地并压缩它们。到目前为止,我已经能够成功提取两个修订版之间的所有更改文件。
为了更进一步,我使用 xcopy 在某个目录中递归地创建文件夹。
假设当我使用 svn diff 命令检查两个修订版时以下文件已更改
/temp1/temp2/temp3/temfile.txt
/temp1/temp21/temp31/tempfile.txt
/temp1/temp2/ (folder created)
/temp1/temp2/temp3 (folder created)
为了使 XCopy 工作,我正在执行
xcopy local/svn/copy/path d:/{folderpath}
需要从上述更改列表中提取文件夹路径的操作
xcopy "C:/LocalSVN/temp1/temp2/temp3/temfile.txt" "d:/temp1/temp2/temp3/"
,例如我需要在我的批处理文件中仅提取文件夹路径和删除文件名。在批处理文件中执行此操作的最佳方法是什么?
有没有不同的方法来实现我想要做的事情?
I have been working on building a packaging utility which basically gets all added/modified files between two SVN revisions, then copies them locally and zips them.So far, I have been able to successfully extract all changed files between two revisions.
To go further, I am using xcopy to recursively create folders at a certain directory.
Assuming that the following files have changed when I check two revisions using svn diff command
/temp1/temp2/temp3/temfile.txt
/temp1/temp21/temp31/tempfile.txt
/temp1/temp2/ (folder created)
/temp1/temp2/temp3 (folder created)
For XCopy to work, I am doing
xcopy local/svn/copy/path d:/{folderpath}
where folderpath needs to be extracted from the above changed list e.g.
xcopy "C:/LocalSVN/temp1/temp2/temp3/temfile.txt" "d:/temp1/temp2/temp3/"
I need to in my batch file, extract only the folder path and remove the file name.What is the best way to do it in a batch file?
Is there a different way to achieve what I am trying to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与如何在批处理文件中获取部分目录路径中几乎相同,
关键是使用 % ~dp 功能,并且由于这只适用于参数(不适用于变量),因此您可以使用 FOR 循环或子例程将变量移至参数中。
It's nearly the same as in How to get a Part of the Directory path in a batch file
The key is to use the %~dp functionality, and as this only works with parameters (not variables), you can use a FOR-Loop or a subroutine to move your variable into a parameter.