Saved Bookmarks
| 1. |
Solve : Counter in for loop doesn't increment? |
|
Answer» To all, To all,basically, you just need a LINE count of the file correct? you can use one of these methods 1) use a unix tools like wc, gawk Code: [Select]# wc -l < file check out the link in my sig to download. (coreutils) 2) if you have constraints about "installing" tools, you can use vbscript Code: [Select]Dim o o=0 Set objFS = CreateObject("Scripting.FileSystemObject") strFile= "C:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile,1) Do Until objFile.AtEndOfLine strLine = objFile.ReadLine o=o+1 Loop WScript.Echo "number of lines: ",o 3) or you can use find Code: [Select]find /c /v "" file Oh God! Another "how do I make this batch work?" question answered by "Get a port of a Unix util". Heaven forbid we should actually answer the *censored* question! April, due to the way that cmd.exe expands variables at runtime, an ordinary variable which is set inside brackets (parentheses) such as in a loop or an extended IF statement, will expand to a blank. You need to know about "delayed expansion". You enable it by putting this line before the loop Code: [Select]setlocal enabledelayedexpansion Then inside the loop you use exclamation marks instead of percent signs for those variables created or modified inside the loop. You can use percent signs for them after the loop has finished. So here is your code rewritten a bit Code: [Select]setlocal enabledelayedexpansion set x=0 for /f %%i in (f.txt) do ( echo A, !x! set /a x=!x!+1 echo %%i echo B, x=!x! ) echo C, x=%x% :ENDQuote from: DIAS DE verano on March 27, 2009, 08:09:08 AM Oh God! Another "how do I make this batch work?" question answered by "Get a port of a Unix util".as long as OP has no constraints, i don't think there's a problem with that. Quote from: ghostdog74 on March 27, 2009, 08:23:40 AM as long as OP has no constraints, i don't think there's a problem with that. I know you don't. |
|