Reputation: 15
How can I edit path which i get from command line arguments and delete last subdirectory?
e.g. I run my batch file with argument: C:\Users\Aga\Desktop\something
and I want to use only "C:\Users\Aga\Desktop" part in my batch file.
Upvotes: 0
Views: 142
Reputation: 38709
Add this as the very first line of your batch file:
@If Not "%~dp1"=="" @(Set "Parent=%~dp1"&Call Set "Parent=%%Parent:~,-1%%")
Then use %Parent% throughout your script as necessary, (%Parent% will be the next directory up the tree if the input was a directory or the container folder if the input was a file).
Upvotes: 1