Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
pstein
- Posts: 125
- Joined: 09 Nov 2011 01:42
#1
Post
by pstein » 09 Sep 2017 03:01
I wrote a batch script which receives files with pathes as parameters.
As
shows the file parameter is always enclosed in double quotes.
How can I remove them in the most easy way (= a one liner)?
Do I really have to use (two) substring operations on the variable?
Peter
Last edited by
Squashman on 09 Sep 2017 11:28, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#2
Post
by Compo » 09 Sep 2017 05:07
Is this what you want?
Code: Select all
@Echo Off
Set "file=%~1"
Echo Processing %file% ...
Pause
-
pstein
- Posts: 125
- Joined: 09 Nov 2011 01:42
#3
Post
by pstein » 09 Sep 2017 07:05
Sorry no.
The problem is that %1 contains from the very beginning a double quotes string like
%1 = "D:\foo\bar\mypic.hpg"
This implicite assignment is not done by me but the WindowsOS when I drap a file onto the batch script
Any other idea?
-
Hackoo
- Posts: 103
- Joined: 15 Apr 2014 17:59
#4
Post
by Hackoo » 09 Sep 2017 07:25
@OP
The solution given by Compo dosen't work for you ??
What is the diffrence between
%1 and
%~1 ?
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 09 Sep 2017 11:18
pstein wrote:Sorry no.
The problem is that %1 contains from the very beginning a double quotes string like
%1 = "D:\foo\bar\mypic.hpg"
This implicite assignment is not done by me but the WindowsOS when I drap a file onto the batch script
Any other idea?
You were given the correct solution. I do drag and drop on pretty much all the batch files I create for my fellow employees. The tilde removes the surrounding quotes.
Open up a cmd prompt and read the help for the CALL and FOR commands.
CALL
Code: Select all
Substitution of batch parameters (%n) has been enhanced. You can
now use the following optional syntax:
%~1 - expands %1 removing any surrounding quotes (")
FOR
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 (")
-
pstein
- Posts: 125
- Joined: 09 Nov 2011 01:42
#6
Post
by pstein » 09 Sep 2017 12:10
Hmm, I tried it again......and it works.
Must have been a bug in command interpreter the previous time
Thank you for the solution and sorry for the confusion