DOS批处理:从相对路径获取最后一个文件夹

发布于 2024-10-05 13:28:20 字数 184 浏览 0 评论 0原文

我在 DOS 批处理文件中有以下值(例如...):

..\Apple\Jones  
..\Banana\Smith  
..\Pear\Wilson  

我需要从每个值中提取姓氏值(“Jones”、“Smith”、“Wilson”)。我可以使用哪一种技术来始终为我提供这些子字符串值?

I have the following values in a DOS batch file (for example...):

..\Apple\Jones  
..\Banana\Smith  
..\Pear\Wilson  

I need to extract the last name values ("Jones", "Smith", "Wilson") from each value. What one technique can I use that will always give me these substring values?

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

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

发布评论

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

评论(2

夏の忆 2024-10-12 13:28:20

According to this topic : What is the best way to do a substring in a batch file?

I suggest you to use

%~n0
向日葵 2024-10-12 13:28:20

我已经为此编写了一个函数。你给它任何路径,它只返回你的文件名或路径名。适用于任何路径:Url、Windows 路径、Unix 路径等...

在批处理脚本末尾复制此函数:(说明如下)

rem ===========================================================================

:Name_From_Path
SetLocal

set _TMP_FOLDERNAME=%1
for %%g in ("%_TMP_FOLDERNAME%") do set _TMP_FOLDERNAME=%%~nxg

EndLocal & set _Name_From_Path=%_TMP_FOLDERNAME%
goto :EOF

rem ===========================================================================

用法:

CALL :Name_Of_Path ..\Apple\Jones
ECHO %_Name_From_Path%

结果:Jones

I already wrote a function for that. You give it any path and it returns you only it's filename or pathname. Works for any path: Url, Windows path, Unix path, etc...

Copy this function at the end of your batch script: (Instructions below)

rem ===========================================================================

:Name_From_Path
SetLocal

set _TMP_FOLDERNAME=%1
for %%g in ("%_TMP_FOLDERNAME%") do set _TMP_FOLDERNAME=%%~nxg

EndLocal & set _Name_From_Path=%_TMP_FOLDERNAME%
goto :EOF

rem ===========================================================================

Usage:

CALL :Name_Of_Path ..\Apple\Jones
ECHO %_Name_From_Path%

Result: Jones

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