Page 1 of 1

how do i get the filesize from a filename? and compare with IF statement

Posted: 04 Apr 2024 07:50
by nnnmmm

Code: Select all

SET Y22=%~dp0Data\minigun_fire.wav
SET Y32=%~dp0Data\minigun_fire.wav

how do i get the filesizes of %Y22% and %Y32%?

IF EXIST "%Y22%"    IF filesize of %Y22%==100   ECHO  Sound MOD 1 installed
IF EXIST "%Y32%"    IF filesize of %Y32%==200   ECHO  Sound MOD 2 installed

IF NOT filesize of %Y22%==100   IF NOT filesize of %Y32%==200  (
ECHO  Sound MOD 1 is NOT installed
ECHO  Sound MOD 2 is NOT installed
GOTO :eof
)

IF filesize of %Y22%==100 (
ECHO  Sound MOD 1 is installed
ECHO  Sound MOD 2 is NOT installed
GOTO :eof
)

Re: how do i get the filesize from a filename? and compare with IF statement

Posted: 04 Apr 2024 08:46
by Squashman
Surprised your searching did not find any of these links.
It is right on the main DosTips.com site library.
https://www.dostips.com/?t=Snippets.FileSize

As well as discussed in several threads. Here is one of them.
viewtopic.php?t=9274

No clue why you would assign the size of the same file to two different variables.

Re: how do i get the filesize from a filename? and compare with IF statement

Posted: 05 Apr 2024 23:43
by nnnmmm

Code: Select all

>Surprised your searching did not find any...
i can get these if /? for /?
but i get no answers from the websearch of "batch command / > ^ /*... etc"
i used to get a headache looking for operator's meanings, it became a habit not to look for them much, then it kind of extended to other searchable areas.

>No clue why you would assign the size of the same file to two different..
my brain would recognize better a year later why i did this way 
i see patterns Y21 Y22 Y31 Y32 but if i introduce a new common variable...i may not recognize it fast  years later why

FOR %%J in ("%Y22%") DO SET YmiFS=%%~zJ
IF /I %YmiFS%==8842 (
IF /I %YmiFS%==35180 (

before my posting, i tried this way
%~z%YY2%
%YY2%~z0
%YY2%~z1
%YY2%~z2... thinking one them might hit the number
see i mimic, i have some knowledge of them but not all

SET Y21=%~dp0Data\!mod - minigun_fire.wav 1.exe
SET Y22=%~dp0Data\minigun_fire.wav
SET Y31=%~dp0Data\!mod - minigun_fire.wav 2.exe
SET Y32=%~dp0Data\minigun_fire.wav
FOR %%J in ("%Y22%") DO SET YmiFS=%%~zJ

   IF /I %VAR%==7 (
      PUSHD "%~dp0data"
      "%Y21%" -OVERWRITE -TIMES=MODIFY
      POPD
   )
   IF /I %VAR%==8 (
      IF /I EXIST "%Y22%" del /q "%Y22%"
   )
thanks for a help