zib24
zib24

Reputation: 169

Using batch script to find filename and run a convert command using that filename

I'm attempting to grab a text file from a folder for conversion to .xls using ssconvert. Currently I have:

for /F %%a in ('dir /b *.txt') do set FileName=%%~na 
ssconvert %FileName%.txt %FileName%.xls

However this results in this being run:

ssconvert thefile .txt thefile .xls

Which obviously doesn't work.

How would I get rid of the space between the FileName variable and the file extension?

Upvotes: 0

Views: 1789

Answers (2)

Dr. belisarius
Dr. belisarius

Reputation: 61056

Try:

for /F %%a in ('dir /b *.txt') do  ssconvert %%~na.txt %%~na.xls

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116170

I think it has something to do with %%~na needing to be just %%a.

Upvotes: 0

Related Questions