| 1. |
Solve : for loop runs twice? |
|
Answer» I have an issue where a for loop from a previous post is running twice. I am trying to get the file properties from the current directory and all sub directories. The only issue is that I am getting double results in my out put file. The issue is some where in the below code. I notice you are using the append redirection symbol >> to write to the csv so each time you run the batch the csv will get bigger. Also take out the GOTO NEXT. You do not need that, nor the :next label. the >> is so the file will be appended to. with out that the file would be recreated each time. That would be fine except this will be ran on all sub directories. the goto was to try and force it to leave the loop without going through it twice. That is the issue I am trying to FIX now. The loop SEEMS to be picking on on the next LINE of the dir.txt. I have also tried to make it create the csv in the for loop and I still have the loop executing twice. Any ideas on how to fix it? Thanks, WayneIf there are 2 lines in the dir.txt then the loop will execute 2 TIMES. Investigate why the dir.txt has 2 lines. Also your "tokens=" block is redundant. yes well is there a way to to only have it run on the 5th line and not the 6th and 7th? Code: [Select] setlocal enabledelayedexpansion set line=1 for /f "delims==" %%v in (dir.txt) do ( if !line! EQU 5 ( SET PS=%%~dpnxv SET FS=%%~zv SET FMDT=%%~tv ) set /a line+=1 ) |
|