Page 1 of 1

delete spaces from a filename before using it as variable

Posted: 10 Nov 2010 11:30
by dwilbank
Hi.
The programmer here at work made a script where we can right click a video file and have it converted to some other format.

The procedure right now is to have no spaces in the filename.

I want to change that, even though I heard it was complicated.

Here's what I was given.

set fileonly=%~n1
set filename=%~dpn1
set filedir=%~dp1

Now I am only at the beginning of my batch script lessons, but I thought I could just add one new line at the beginning to take care of matters.

set n1=%n1: =_%
set fileonly=%~n1
set filename=%~dpn1
set filedir=%~dp1

Apparently I don't understand yet what the tilde is doing in his original code, but where am I going wrong?

And is the n1 the assumed result of a right click selection?
I never saw it set as a variable anywhere else...

Thanks for any help

Re: delete spaces from a filename before using it as variabl

Posted: 12 Nov 2010 02:26
by amel27
you must add dbl quotes in all commands with file names, if not present:

%~n1 -> "%~n1"
%~dpn1 -> "%~dpn1"
%~dp1 -> "%~dp1"

Re: delete spaces from a filename before using it as variabl

Posted: 15 Nov 2010 15:43
by dwilbank
Thx but there is something more mysterious going on with these variables...
It didn't find the file at all...
I'll have to study some more...