Is that possible save a special character " to a string without new line? I tried below codes ,but none of them working:
echo|set /p=""" >>C:\text.txt
echo|set /p=" >>C:\text.txt
echo|set /p=^" >>C:\text.txt
set /p=""" <nul >> C:\text.txt
set /p=" <nul >> C:\text.txt
set /p=^" <nul >> C:\text.txt
You almost had it
<nul >"file.txt" set/p="""
but, as Squashman points, if you try to write to the root of your drive, you will need an elevated prompt
Here is a slightly different method which does not require the redirection to be put in front of the set /P
command:
set /P =""^" < nul >> "C:\text.txt"
Since the last of the three quotation marks is escaped like ^"
, the remaining command line portion does not appear quoted and therefore, the redirection operators <
and >>
are recognised.
Not a one-liner in the command-prompt but as a batch-file the following works for me:
>>output.txt (
echo|set/p="""
)
Or if you want to hit return to write it use the following, very similar one:
>>output.txt (
set /p=""" < nul
)
One could as well establish it to be a kind of a function to use dynamically:
>>"%~dp1" (
echo|set/p="""
)
To use this one, you pass the filename as first command-line argument as the following:
addQuoteTo.bat "C:\my Path\toFile\file.txt"
Was an interesting thing to play around with :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With