Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#1
Post
by goodywp » 22 Jan 2018 13:46
Hi
I have a txt file like this:
"abcdef/edc/ec/c/"
"abec/sdlkd/dlkdk/"
................
What is the easiest way to trim off the double quote in each line in this txt file..
abcdef/edc/ec/c/
abec/sdlkd/dlkdk/
I tried this way and still got the quote...
Code: Select all
@echo off
If exist schpacklist.txt (del schpacklist.txt)
setlocal EnableDelayedExpansion
for /f "delims=" %%A in (sch_pack_list.txt) do (
set a=%%A
echo !a:"=!
)>>schpacklist.txt
Thanks
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 22 Jan 2018 16:41
Did you read the help file for the FOR command.
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 (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#3
Post
by goodywp » 23 Jan 2018 10:06
Squashman wrote: ↑22 Jan 2018 16:41
Did you read the help file for the FOR command.
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 (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
I tried this
Code: Select all
@echo off
If exist schpacklist.txt (del schpacklist.txt)
set ofile=sch_pack_list.txt
FOR /F "tokens=*" %%I IN (%ofile%) DO (
set line=%%~I
echo %line%
)>>schpacklist.txt
and still got the quote ????
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 23 Jan 2018 10:42
What the heck are you doing? What is the reason for saving the line into a variable before you try to echo it? And if you try to do so why didn't you use delayed expansion in a parenthesized block?
Steffen
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#5
Post
by goodywp » 23 Jan 2018 12:37
aGerman wrote: ↑23 Jan 2018 10:42
What the heck are you doing? What is the reason for saving the line into a variable before you try to echo it? And if you try to do so why didn't you use delayed expansion in a parenthesized block?
Steffen
tried and got
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#6
Post
by aGerman » 23 Jan 2018 12:54
Did you read my comments and did you understand what I wrote? What did you try?
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#7
Post
by goodywp » 23 Jan 2018 13:02
aGerman wrote: ↑23 Jan 2018 12:54
Did you read my comments and did you understand what I wrote? What did you try?
add delayed expansion in a parenthesized block
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 23 Jan 2018 13:09
I give up.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#9
Post
by Squashman » 23 Jan 2018 13:31
If you make code changes you need to repost the code you are using. Just saying you made a code change and then showing us the output of the code change doesn't help anyone understand what is wrong.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#10
Post
by Squashman » 23 Jan 2018 13:39
goodywp wrote: ↑23 Jan 2018 13:02
aGerman wrote: ↑23 Jan 2018 12:54
Did you read my comments and did you understand what I wrote? What did you try?
add delayed expansion in a parenthesized block
Delayed Expansion was explained to you in your
previous question. This is the second time I have linked back to that question to show you that we had already had the answer to a new question you posted.
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#11
Post
by ShadowThief » 23 Jan 2018 20:24
goodywp wrote: ↑23 Jan 2018 13:02
aGerman wrote: ↑23 Jan 2018 12:54
Did you read my comments and did you understand what I wrote? What did you try?
add delayed expansion in a parenthesized block
Cool, now try doing it correctly.
-
goodywp
- Posts: 265
- Joined: 31 Jul 2017 09:57
#12
Post
by goodywp » 26 Jan 2018 15:46
ShadowThief wrote: ↑23 Jan 2018 20:24
goodywp wrote: ↑23 Jan 2018 13:02
aGerman wrote: ↑23 Jan 2018 12:54
Did you read my comments and did you understand what I wrote? What did you try?
add delayed expansion in a parenthesized block
Cool, now try doing it correctly.
Thank you!