使用 DOS 批处理脚本获取特定文件的父目录名称 [英] Get parent directory name for a particular file using DOS Batch scripting
本文介绍了使用 DOS 批处理脚本获取特定文件的父目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 DOS 中查找文件的父目录名称
I need to find the name of the parent directory for a file in DOS
例如
假设这是目录
C: estpacka.txt
我有一个询问我文件名的脚本
I have a script which asks me the file name
C:\>getname.bat
enter file name: c: estpacka.txt
现在脚本应该只返回文件的父名称.
now the script should return just the parent name of the file.
pack
而不是文件的整个父路径.
and NOT the entire parent path to the file.
c: estpack
推荐答案
参见 这个 问题
@echo OFF
set mydir="%~p1"
SET mydir=%mydir:=;%
for /F "tokens=* delims=;" %%i IN (%mydir%) DO call :LAST_FOLDER %%i
goto :EOF
:LAST_FOLDER
if "%1"=="" (
@echo %LAST%
goto :EOF
)
set LAST=%1
SHIFT
goto :LAST_FOLDER
这篇关于使用 DOS 批处理脚本获取特定文件的父目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文