windows - Collect changing/dynamic variable from batch, and transfer to C# (Visual Studio 2017) -
so writing simple batch program search specified file:
@echo off del temp1.txt del temp2.txt set curfile=0 set percentage=0 set numfiles=0 /f "tokens=*" %%n in ('dir %searchfor% /b /s') set numfiles=%numfiles%+1 /f "tokens=*" %%n in ('dir %searchfor% /b /s') ( set /a "rand=%random% % 10" set /a "rand=rand*1000" ping 1.1.1.1 -n 1 -w %rand%> nul set curfile=%curfile%+1 set percentage=%curfile%*100 set percentage=%percentage%/%numfiles% set p=%%n if defined p ( echo %p% >>temp1.txt echo %percentage% >>temp2.txt echo %numfiles% >>temp3.txt ))
so not familiar c# @ all, seems intuitive. goal create c# based ui this, can these tasks:
- run batch script (let's call batch searchr.bat)
as batch file searching through files, , updating variables gives these values:
filepath of file found (defined %%n , %p%) percentage complete of search through files total number of files on computer
our c# program collect these variables , have access them, , update variables corresponding files update.
so want have c# program running, , batch @ same time, , c# reading outputs of batch file live, update.
i tried keep batch file intuitive possible, there stuff didn't care polish or optimize.
why not in pure batch?
@echo off setlocal enabledelayedexpansion rem search mask set "searchfor=*.*" rem needed show progress set/a curfile=0, percentage=0, numfiles=0 /f "tokens=1,2 delims=#" %%a in ('"prompt #$h#$e & echo on & %%b in (1) rem"') set "del=%%a" /l %%i in (1,1,39) set "del_line=!del_line!!del!!del!" rem file number /f "tokens=*" %%n in ('dir /a-d-s-h /b "%searchfor%" ^| find /v /c ""') set "numfiles=%%n" & echo/processing folder %%~dpn&echo/ ::now work /f "tokens=*" %%n in ('dir /a-d-s-h /b "%searchfor%"') ( set/a curfile+=1, percentage=curfile*100/%numfiles% <nul set/p=!del_line!processing !curfile! of %numfiles%, !percentage!%%. %%~nxn rem ... rem code here rem ... ping 1.1.1.1 -n 1 -w 500> nul ) echo/&echo/done. endlocal exit/b
Comments
Post a Comment