Saved Bookmarks
| 1. |
Solve : Debugging - FOR loop? |
|
Answer» cd \ setlocal enableextensions enabledelayedexpansion net view > list.txt set /a LNE=0 :find set /a LNE=%LNE%+1 for /f "skip=%LNE%" %%m in ('findstr . list.txt') do ( goto find ) set /a SKP=3 :begin if %SKP% GTR %LNE%-1 goto end :first for /f "skip=%SKP%" %%i in ('findstr . list.txt') do ( set PC=%%i if exist %PC%\multimedia goto go goto reset :go DIR %PC%\multimedia /s > find.txt findstr drvmgt.dll %cd%\find.txt >nul && echo %PC% >> pos.txt :reset set /a SKP=%SKP%+1 goto begin ) :end Here is an excerpt of my code (i.e. just CUT out the parts I need), that so far is meant to: 1. Send the output of net view to a text file 2. Check how many lines are in the test file 3a. Search for the multimedia folder on the remote computer 3b. Then send the directory of it to a text file 3c. Then search for a particular file, and if found, send the PC name to another text file However, just searching through my network of computers, there is no multimedia folder in there, so that eliminates some of the steps. However, my for loop is causing me some problems. The for itself isn't the problem, but I can't seem to isolate the exact cause of the unexpected error (from what I can read in a millisecond: . was unexpected at the time.) Anyway, any help would be appreciated. Thanks. I think we already had this conversation. The run log of your code looks like this: Code: [Select]D:\>setlocal enableextensions enabledelayedexpansion D:\>net view 1>list.txt D:\>set /a LNE=0 D:\>set /a LNE=0+1 D:\>for /F "skip=1" %m in ('findstr . list.txt') do (goto find ) D:\>(goto find ) D:\>set /a LNE=1+1 D:\>for /F "skip=2" %m in ('findstr . list.txt') do (goto find ) D:\>(goto find ) D:\>set /a LNE=2+1 D:\>for /F "skip=3" %m in ('findstr . list.txt') do (goto find ) D:\>(goto find ) D:\>set /a LNE=3+1 D:\>for /F "skip=4" %m in ('findstr . list.txt') do (goto find ) D:\>set /a SKP=3 D:\>if 3 GTR 4-1 goto end D:\>for /F "skip=3" %i in ('findstr . list.txt') do ( Set PC=%i if exist \multimedia goto go goto reset dir \multimedia /s 1>find.txt findstr drvmgt.dll D:\\find.txt 1>nul && echo 1>>pos.txt set /a SKP=3+1 goto begin ) D:\>( set PC=The if exist \multimedia goto go goto reset dir \multimedia /s 1>find.txt findstr drvmgt.dll D:\\find.txt 1>nul && echo 1>>pos.txt set /a SKP=3+1 goto begin ) D:\>set /a SKP=3+1 D:\>goto begin D:\>if 4 GTR 4-1 goto end D:\>for /F "skip=4" %i in ('findstr . list.txt') do ( set PC=%i if exist The\multimedia goto go goto reset dir The\multimedia /s 1>find.txt findstr drvmgt.dll D:\\find.txt 1>nul && echo The 1>>pos.txt set /a SKP=4+1 goto begin ) Doesn't seem to be a syntax error. I think it would be easier if you only processed the net view lines that CONTAIN any relevant data instead of hunting for dots and skipping headers. This little snippet should do just that: Code: [Select]for /f "tokens=1-2 delims=\ " %%x in ('net view ^| find "\\"') do (.... I'll leave it to you to fill in the do logic. Note: %%x contains the computer name (without the backslashes; if you want the backslashes, REMOVE the entire delims clause); keep in mind that one of the computers in the net view list is yours. PS. Pretty sure that if %SKP% GTR %LNE%-1 goto end does a string comparison and in any CASE if statments do not do arithmetic.For some reason, there is still the same error as last time. This is really annoying me now... there seems to be no apparent cause... I even tried removing one line at a time to see what was causing the fault, but to no avail... However, in the meantime I managed to make the rest of my code bug-free! But, although it was quite helpful, that's not much of a substitute. Anyway, I'll get back to work on the for loop again, and see if I can't get this thing to work... Thanks for your help --Dark Blade EDIT: But wait! It works now!!! I just replaced the PC variable with %%i (they are the same, after all), and then it worked! I always thought that creating a new variable was unnecessary.... My batch file is working perfectly now. That said, I haven't actually had a proper test run on any computers with \multimedia (my school has them, though). But I'm optimistic. Thanks again |
|