1.

Solve : Set a multiline variable in batch?

Answer»

On last time. Don't put multiple;e lines into a variable.
It is FORBIDDEN, not allowed, senseless, worthless and futile.

It is like trying to brush your teeth with hand soap.

Stop with the lines in a variable .
Tell us what your really need to do.

Putting lines into a variable is not what real men do. do.
Go read a book. Or get a tutor.

Quote from: Geek-9pm on February 02, 2016, 10:55:27 PM

On last time. Don't put multiple;e lines into a variable.
It is forbidden, not allowed, senseless, worthless and futile.

It is like trying to brush your teeth with hand soap.

Stop with the lines in a variable and we will tell you how to do what your want to do/.
Putting lines into a variable is not what real men do. do.
Go read a book. Or get a tutor.

Well im not the one who asked for this, and i didn't really put multiple lines in a variable, just called the "echo." command and turned it into a variable. and added after some regular code, just trying to help. im not a big fan of the whole multi lined variable thing myself. kinda is nonsense really. im sure in some very rare case it could be useful but still it's not like it's the most biggest breakthrough in computer programming ever, and even it did have a purpose, what are the odds and why would it even be that important? multi lined variables are for people who are to lazy to either copy and paste the code or edit it them self's. so i'm with you on this one.

almost 5 pages too, patio, i think your a wizard. Quote from: Geek-9pm on February 02, 2016, 10:55:27 PM
On last time. Don't put multiple;e lines into a variable.
It is forbidden, not allowed, senseless, worthless and futile.

It is like trying to brush your teeth with hand soap.

Stop with the lines in a variable .
Tell us what your really need to do.

Putting lines into a variable is not what real men do. do.
Go read a book. Or get a tutor.
Wait, what? I'm not a batch developer but I know that in literally any language I've seen it's totally normal to have multiple lines in a variable, all a new line is is a special character. Your forum post has multiple lines in it and I'd hazard a guess that at some point in the rendering of this page the body of your post is loaded into a single variable in the backend of this forum.

Quote from: zask on February 02, 2016, 10:59:39 PM
multi lined variables are for people who are to lazy to either copy and paste the code or edit it them self's. so i'm with you on this one.
They are for people who need to handle strings that contain multiple lines. In the initial question for example they wanted to replace a single line in the input with multiple lines, this is totally standard practice in many programs. Being lazy doesn't COME into it at all, besides, in fact, copying and pasting code is generally seen as the lazy way to do things - https://en.wikipedia.org/wiki/Copy_and_paste_programmingCode: [Select]@echo off
set "src=C:\path\to\source\files"
set "dst=C:\path\to\destination\files"
pushd "%src%"

for /f "delims=" %%a in ('dir /b /a-d "*.vrt" ') do (
echo Processing "%%a"
set "stop="
(
for /f "usebackq delims=" %%b in ("%%a") do (
echo(%%b
if not defined stop type "file2.vrt" & echo(
set stop=are-we-there-yet?
)
)>"%dst%\%%a.tmp"
move /y "%dst%\%%a.tmp" "%dst%\%%a" >nul
)
echo done
pause

A file should now be created for each VRT file. The redirection to the file was at the wrong level of parentheses and the move command is necessary again.

Test it on sample files first.Quote from: camerongray on February 03, 2016, 03:46:50 AM
Wait, what? I'm not a batch developer but I know that in literally any language I've seen it's totally normal to have multiple lines in a variable

It's not normal in batch scripts though. Quote from: foxidrive on February 03, 2016, 04:33:39 AM
It's not normal in batch scripts though.
Right. Here is the fundamental way the command interpreter works:
command p1 p2 p3 ...
Batch script is for a shell tool, console e utility. One line is a full expression. INTERACTIVE work from the a console would not not normally expect multiple Lines.
Also, spaces are the DEFAULT delimiter.
A batch file is not a word processor, not a database or a universal toolkit.
And yes, one could brush his teeth with hand soap. But why would he?
I am outhitting the THREAD. Really. I am rolling my eyes. Quote from: camerongray on February 03, 2016, 03:46:50 AM
Wait, what? I'm not a batch developer but I know that in literally any language I've seen it's totally normal to have multiple lines in a variable, all a new line is is a special character. Your forum post has multiple lines in it and I'd hazard a guess that at some point in the rendering of this page the body of your post is loaded into a single variable in the backend of this forum.
They are for people who need to handle strings that contain multiple lines. In the initial question for example they wanted to replace a single line in the input with multiple lines, this is totally standard practice in many programs. Being lazy doesn't come into it at all, besides, in fact, copying and pasting code is generally seen as the lazy way to do things - https://en.wikipedia.org/wiki/Copy_and_paste_programming

Yeah, but i think it's different in batch, mainly because it was never really intended for multi lined variables, when i was talking about copy and pasting the code i was referring to pasting a code that he had already made into another file and edit it himself, instead of putting in a variable. Yeah there is a lot of languages that can do it, but it's not a good practice in batch, and there are a lot of reasons why its not such a good idea. One good reason why is the example that Geek-9pm posted above, luckily the method i posted doesn't actually create a multi lined, but mimics it's technique with single lines instead. But still, in batch i hardly find a point for this . it does nothing but make your code even more difficult to comprehend / more difficult add edits for later use / and just plane up wastes bites in your file. if you wanted to use the command for later use just copy and paste it again, what ever you wanted to change in the text, just change it with regular variables. If you needed to completely store multiple lines of code, just send it to a file and call it inside the batch file. Notice now Geek-9pm states that "it's like brushing your teeth with soap"...? It is possible but there just isn't any point because it makes things more difficult. now more powerful languages like C++ is fine, but batch can only go so far.Quote from: foxidrive on February 03, 2016, 04:26:22 AM
Code: [Select]@echo off
set "src=C:\path\to\source\files"
set "dst=C:\path\to\destination\files"
pushd "%src%"

for /f "delims=" %%a in ('dir /b /a-d "*.vrt" ') do (
echo Processing "%%a"
set "stop="
(
for /f "usebackq delims=" %%b in ("%%a") do (
echo(%%b
if not defined stop type "file2.vrt" & echo(
set stop=are-we-there-yet?
)
)>"%dst%\%%a.tmp"
move /y "%dst%\%%a.tmp" "%dst%\%%a" >nul
)
echo done
pause

A file should now be created for each VRT file. The redirection to the file was at the wrong level of parentheses and the move command is necessary again.

Test it on sample files first.

Thanks!


Discussion

No Comment Found