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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

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

#1 Post by nnnmmm » 04 Apr 2024 07:50

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
)

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

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

#2 Post by Squashman » 04 Apr 2024 08:46

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.

nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

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

#3 Post by nnnmmm » 05 Apr 2024 23:43

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

Post Reply