| 1. |
Solve : Trying to align output? |
|
Answer» I am working on a batch file where I want it to list stuff about the computer such as computer name, version of windows, disk drive size, etc. I have the commands to gather the info, and its all going into a textfile that then gets mailed to me. What I want is it to look neater. Code: [Select]echo off Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" VARIABLE to work. Also, I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP? From the FOR /? in cmd prompt: FOR %variable IN (set) DO command [command-PARAMETERS] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used. command Specifies the command to carry out for each file. command-parameters Specifies parameters or switches for the specified command. To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I. Other than that, all in all, it looks like it would work in Vista and 7 just the same. Quote from: Raven19528 on October 14, 2011, 12:23:27 PM I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP? In Windows NT family (2000, XP, Vista, Windows 7, plus Server 2003 & 2008), you can use most of ASCII 33 (!) to 126 (~) the exceptions are, as far as I can see: 34 (") 37 (%) 38 (&) 44(,) 59( 60(<) 61(=) 62(>) 124 ) but the documentation only mentions A-Z and a-z, POSSIBLY to keep things simple for people learning batch scripting. for example Code: [Select]C:\>for %# in (a b c) do echo %# a b c C:\>for %$ in (a b c) do echo %$ a b c Quote from: Raven19528 on October 14, 2011, 12:23:27 PM Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" variable to work. Oops yes, thank you for the correction, I can only blame the Friday night rums and Cokes for the omission. Your other query has been ANSWERED by ST and I can only add that most printable ASCII characters are acceptable in a For loop, including a few of the exceptions noted by ST, altho' there are some which must be Escaped. Try this. If it doesn't work I'll think up some excuse!! (note the use of the Esc char ^ and other chars " and #): Code: [Select]echo off cls setlocal enabledelayedexpansion for /f "tokens=1* delims=:" %%^" in (trial.txt) do ( set first=%%": . echo !first:~0,17!%%# ) |
|