Truncating file path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
airkemp
Posts: 5
Joined: 03 Oct 2011 09:29

Truncating file path

#1 Post by airkemp » 03 Oct 2011 09:41

Hi There,

I am given a folder path through an input, it comes in as %1 and prints the following;

C:\Folder1\Folder2\Folder3\Folder4

How can i ommit the first 3 paths (including the drive letter), printing just;

Folder3\Folder4

Any help you be appriciated,

Many Thanks

Alex

colargol
Posts: 49
Joined: 28 Sep 2011 13:23
Location: france

Re: Truncating file path

#2 Post by colargol » 03 Oct 2011 10:04

Code: Select all

for /f "tokens=3* delims=\" %%a in ("%~1") do (set trunc=%%b)
echo %trunc%


hope **consored** will correct if I'm wrong :)

airkemp
Posts: 5
Joined: 03 Oct 2011 09:29

Re: Truncating file path

#3 Post by airkemp » 04 Oct 2011 06:47

Works a charm!

Thanks alot

Alex

Post Reply