I want to have a batch file which checks what the filesize
is of a file.
If it is bigger than %somany% kbytes,
it should redirect with GOTO to somewhere else.
Example:
[check for filesize] IF %file% [filesize thing Bigger than] GOTO No echo Great! Your filesize is smaller than %somany% kbytes. pause exit :no echo Um... You have a big filesize. pause exit
Locate the file or folder whose size you would like to view. Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.
If you just open the batch file, click on the window, and then click "properties", and then to "layout", and scroll down to "Window Size", you can edit it from there.
What we need is to open the terminal and type du -sh file name in the prompt. The file size will be listed on the first column. The size will be displayed in Human Readable Format. This means we can see file sizes in Bytes, Kilobytes, Megabytes, Gigabytes, etc.
If the file name is used as a parameter to the batch file, all you need is %~z1
(1 means first parameter)
If the file name is not a parameter, you can do something like:
@echo off setlocal set file="test.cmd" set maxbytesize=1000 FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA if %size% LSS %maxbytesize% ( echo.File is ^< %maxbytesize% bytes ) ELSE ( echo.File is ^>= %maxbytesize% bytes )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With