C
C#13mo ago
Vogel

❔ 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
4 Replies
Jimmacle
Jimmacle13mo ago
to clarify, is this a C# question or a batch question?
Vogel
Vogel13mo ago
batch
Shinigami
Shinigami13mo ago
If you know the path, can't you just delete the dir2 recursively?
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts