本文介绍了批处理脚本:如何在没有完整路径的情况下获取父目录名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理一个处理文件夹的脚本,并且其中总是有一个文件需要重命名。新名称应为父目录名称。如何在批处理文件中获取此文件? dir的完整路径是已知的。
I'm working on a script that processes a folder and there is always one file in it I need to rename. The new name should be the parent directory name. How do I get this in a batch file? The full path to the dir is known.
推荐答案
目前尚不清楚脚本应该如何熟悉该路径问题,但以下示例至少应使您了解如何进行操作:
It is not very clear how the script is supposed to become acquainted with the path in question, but the following example should at least give you an idea of how to proceed:
FOR %%D IN ("%CD%") DO SET "DirName=%%~nxD"
ECHO %DirName%
此脚本从 CD
变量获取路径,并仅从其中提取名称到 DirName
。
This script gets the path from the CD
variable and extracts the name only from it to DirName
.
这篇关于批处理脚本:如何在没有完整路径的情况下获取父目录名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!