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.
相关问题
- How to access the camera from my Windows Phone 8 a
- xcopy include folder
- Batch file if string starts by
- Jenkins - cmd is not recognized
- String Manipulation with case sensitivity
相关文章
- Extracting columns from text file using Perl one-l
- Loss of variables switching orientations
- What is the limit in size of a Php variable when s
- How can one batch file get the exit code of anothe
- Directory.CreateDirectory Latency Issue?
- How to make jenkins fail at a failing windows batc
- Makefile and use of $$
- How can i list only the folders in zip archive in
You can use built-in
bash
tricks:Explanations:
#
means 'remove the pattern from the begining'#
means 'remove the longer possible pattern'*/
is the patternUsing built-in
bash
avoid to call an external command (i.e.basename
) therefore this optimises you script. However the script is less portable.You can use
basename
command: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:
This script gets the path from the
CD
variable and extracts the name only from it toDirName
.