How to remove a path from all lines in file? Filenames should be kept.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

How to remove a path from all lines in file? Filenames should be kept.

#1 Post by pstein » 23 Feb 2022 09:42

In a text file many lines contain a path + filename each

How can I (from a DOS Batch script) remove all the paths (including the last \") from all lines which contain a path+filename?
Just the filename should remain.

If a line is empty or contain just other text then nothing should happen.

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: How to remove a path from all lines in file? Filenames should be kept.

#2 Post by Squashman » 23 Feb 2022 18:31

I just went back and looked at a lot of your threads. I see no reason why you shouldn't know how to do this already with all of the code you have been given the past 10 years.
Many of your threads show the usage of the `FOR` command modifiers that allows you to split apart the path and file name and file extension. There has been code in your questions that use all three of those modifiers.

Code: Select all

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file

Post Reply