I'm new here and not used to writing batch files
I tried writing a file that does the following
Code: Select all
start:
IF the free diskspace on C:\ is over 2GB
do nothing
ELSE
delete the alfabetically first subdirectory of C:\measuringresults
jump to start
END IF
END
I created the following file
NOTE that the language of the system used is Dutch, hence the diskspace deleting the first 5 words
Code: Select all
code:
@echo off
color f0
:begin
fsutil volume diskfree c: > C:\temp.txt
setlocal
for /f "tokens=1*" %%a in (C:\temp.txt) do (
set vrij=%%b
goto endloop1
)
:endloop1
pause
for /f "tokens=1,2,3,4,5 delims=/ " %%a in ("%vrij%") do set size=%%e
if %size% GTR 2000000000 goto end
call listEN.bat
pause
for /f "tokens=2*" %%a in (C:\temp.txt) do (
set name=%%a
echo name
goto endloop2
)
:endloop2
echo %name%
echo del C:\measuringresults\%name%
pause
:end
del C:\temp.txt
Code: Select all
code listEN.bat:
@echo off
dir /B measuringresults > C:\temp.txt
what happens is this:
the result of the fsutil volume diskree C: function is stored in C:\tempvolfile
the number of free bytes is filtered and stored in "size"
listEN.bat gets called an executed correctly, temp.txt contains the subdirectories as it should
IT GOES WRONG HERE: I want "name" to contain the first subdirectory of "measuringresults" = the first line from temp.txt . It stays empty though
I can't figure out why I can't get "name" get the value of the first string from the temp file, while I could get "size" to the number of free bytes
Anyone here who can help me out?
Thx in advance