| 1. |
Solve : list dir into variable? |
|
Answer» I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using. I've found a few examples around the internet, but NONE of them seem to work. I'm trying to set up an email alert (using blat) for a batch file and I've got most of it done. One thing remains.... I want to include the directory list in the body of the email, but am having trouble figuring out how to add the directory list into the variable that I'm using. Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email. dir /b >file.txtIt might be worth pointing out that the HTML line-break element is either or , and never . If the email is a plain text format and not HTML format (or the email software interprets it as plain text), you will not get the line breaks you want and should use the character code(s) for a line break instead.Quote from: TechnoGeek on September 11, 2012, 11:06:57 PM It might be worth pointing out that the HTML line-break element is either look at your response and you'll see why I put the \ in there. Blat has a handy little -html flag that formats the message at html.... I think we'll do fine with that. I tried using line break character codes, but none of them seemed to work for Outlook... Quote from: Lemonilla on September 11, 2012, 07:06:24 PM if you want the characters '<\br>' you should be able to change 'echo !a! \ %%G' to 'echo !a! ^<br\^> %%G' Thanks Lemonilla. the ^ fix worked. Now I'm getting some other errors when it gets to the part with the 3,1000 in it. Also, I can't get the ^ fix to work on other statements, such as: SET emailbody=%emailbody%^%timestamp% Quote from: foxidrive on September 11, 2012, 07:39:02 PM Another way is to simply create a file containing the DIR list and attach it to the email using BLAT or get BLAT to include it as the body of the email. I thought about that, but I could only make the list an attachment. I would rather have it as part of the message. But the way it's going, I might resort to that. Edit: I just ran a test with setting a variable with a ^ in it. Code: [Select]SET test=blahblah^<br^>morestuff ECHO %test% The System cannot find the file specified. Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of USED variables, test has the correct string, but I just can't use it for anything..... What am I missing?Quote from: michaewlewis on September 12, 2012, 09:36:30 AM Why would it return that when I run the ECHO statement? If I enter SET, and look through the list of used variables, test has the correct string, but I just can't use it for anything..... The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes Code: [Select][64] [64]C:\>SET test=blahblah^<br^>morestuff C:\>echo %test% The system cannot find the file specified. [64]C:\>echo "%test%" "blahblah<br>morestuff" Quote from: Salmon Trout on September 12, 2012, 12:04:38 PM The string %test% contains a < character and a > character. You had to escape them to get them in there, but when you echo %test% the shell expands the variable and finds them. To stop that happening use quotes Is there a way to remove the quotes from the output, while still ignoring the < and >?Quote from: Lemonilla on September 13, 2012, 01:42:06 PM Is there a way to remove the quotes from the output, while still ignoring the < and >? Get the string with quotes into a FOR variable and strip the quotes off with the ~ (tilde) modifier. Full details in the FOR help (FOR /?) Code: [Select]C:\>SET test=blahblah^<br^>morestuff C:\>echo %test% The system cannot find the file specified. C:\>echo "%test%" "blahblah<br>morestuff" C:\>for %A in ("%test%") do @echo %~A blahblah<br>morestuff Remember you use one percent sign for the FOR variable (e.g. %A) at the prompt, but TWO in a batch script (e.g. %%A). |
|