Vogel
Vogel
CC#
Created by Vogel on 6/15/2023 in #help
❔ Batch script - remove last two folders from filepath
I have a filepath for example: C:\User...\dir1\dir2\dir3. How to delete last two dirs (dir2 and dir3) from a filepath? I have created simple function that only remove last dir from the path in a batch script like this: set Dir="C:\User...\dir1\dir2\dir3" for /D %%D in (%Dir%) do ( set "new_dir=%%~dpD" ) echo "my new path" %new_dir% How can I expand to to remove also a dir2 from a filepath? example path: C:\User...\dir1\dir2\dir3 Target path is: C:\User...\dir1
5 replies