Jump to content
MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. ×

[Help] Batch - Remove Trailing Space

Recommended Posts

I got another strange batch coding Q: that I cant seem to find the answer to...

I have a txt files with a list of files contained within it - Ex:

"C:\Documents and Settings\User\Local Settings\Temp\TDSS6784.tmp "

"C:\Documents and Settings\User\Local Settings\Temp\TDSS684f.tmp "

"C:\Documents and Settings\User\Local Settings\Temp\TDSS9f9b.tmp "

How do I remove the trailing space after the file extension?

looking at variable modifiers... %var:~0,-1% Should do what I need, however, how do I implement this to process all the lines in my txt file.

I could use an array, but I don't know the proper syntax of how to encorperate the modifier, as the below code does not work properly:

For /f "tokens=*" %%I in (FileList.txt) do SET Ifiles=%%I&&Echo %Ifiles:~0,-1%>>CorrectedFiles.txt

as it just places a bunch of ~0,-1 's in CorrectedFiles.txt

Do I have a typo, or is there a better way of doing this within a batch file?

Thanks a million

Link to comment
Share on other sites

Well your biggest error was that you'd have needed to enable delayed expansion!

Here's an alternative

@Echo off&Setlocal enableextensions
For /f "delims=" %%# In (FileList.txt) Do Set "Ifiles=%%~#"&&Call :SUB %%Ifiles%%
Goto :Eof

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...