Command help on file names

Sep 30, 2016
11
0
Hi,

I knew that years ago I’ve already used it but now I can’t get it up running …
I want a TCC command running on several jpg’s and the output should consider only the file name and not the extension.

I’ve tried this without success:

for %a in (St-Tropez-1984*.jpg) do cwebp -q 80 %a -o %@name[%file].webp

E.g. one file name is St-Tropez-1984_1280w.jpg and the output name should be St-Tropez-1984_1280w.webp.
If I’m just using %a.webp for the output the “.jpg” part isn’t discarded and I got file names like St-Tropez-1984_1280w.jpg.webp.

Thanks in advance.
Ulrich
 
Dec 10, 2014
66
1
You're using %a and then another var in %@name[%file]?

If you're not wild about 1-line shell scripts try to write a quick .btm for better debugging, you can echo the vars or use the tcc debugger ...

Code:
do imgin in /a:-d St-Tropez-1984*.jpg
set imgout=%@name[%imgin].webp
cwebp %imgin -o %imgout
if not isfile %imgout .or. %? ne 0 echo error!
enddo

... you might have to work around special chars with setdos /x
 
Sep 30, 2016
11
0
I will try your BTM, thank you (I don't understand everything now).
My goal is to separate the file name and extension and process the file(s) so that the CWEBP program can add its webp extension but take the jpg extension for input. If it works then I could write a BTM that does the command on all jpegs in a folder and process them to webp.
 
Sep 30, 2016
11
0
The BTM works very well, thank you!
What I do not understand is the switch "/a:-d". Is this an attribute selection with directories? And why is this needed?
Ah, and now thanks to your BTM I got my one-liner working:
for %a in (*.jpg) do cwebp -q 80 %a -o %@name[%a].webp
This will convert every JPG file to WEBP.
Thanks again.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,394
83
Albuquerque, NM
prospero.unm.edu
The BTM works very well, thank you!
What I do not understand is the switch "/a:-d". Is this an attribute selection with directories? And why is this needed?
He's excluding directories. DO, by default, returns both files and directories. DO /A:-D returns only files. DO /A:D (without the minus) would return only directories, not files.

In fact it's unlikely that you have any subdirectories that would match that wildcard pattern. Juppy is being professional here: considering the unlikely, and checking for errors.
 
Sep 30, 2016
11
0
Thank you very much for the explanation. I did read the help file but somehow missed the little "-" and wondered why an attribute "directory" is needed ...