I have a directory for which I want to list all the .doc
files with a ;
.
I know the following batch command echos all the files:
for /r %%i In (*.doc) DO echo %%i
But now I want to put them all in a variable, add a ;
in between and echo them all at once.
How can I do that?
set myvar="the list: " for /r %%i In (*.doc) DO <what?> echo %myvar%
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
Content writing to files is also done with the help of the double redirection filter >>. This filter can be used to append any output to a file. Following is a simple example of how to create a file using the redirection command to append data to files.
In PowerShell, string concatenation is primarily achieved by using the “+” operator. There are also other ways like enclosing the strings inside double quotes, using a join operator, or using the -f operator. $str1="My name is vignesh."
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
What about:
@echo off set myvar="the list: " for /r %%i in (*.doc) DO call :concat %%i echo %myvar% goto :eof :concat set myvar=%myvar% %1; goto :eof
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