Using 'File size' as a conditional branch?

I know I can use
" File.exists?($game_variables[x]) " as a conditional branch.
Are there other file properties I can use in conditional branches? Like file size for example.
If so, how would I express this as code?

Thanks in advance!
The file size it's not that reliable as you might think. Or do you want to measure them in bytes? 😛 There might be a chance that a new save file is not as large as an old one because you deleted some scripts that required more data that the existing ones.

Please choose a different method to differentiate them.
Hiya! I've moved this RGSSx script support, thank you!
I wouldnt be checking the size of the save, i'd be checking the size of a file determined by a variable to see whether its actually a functional file or a placeholder to help me organize stuff.

I was going to use a size check (file is greater than say 20 kbs) to trigger a true response for my if/else branch. otherwise (file is less than 20 kbs, a placeholder file) returns as a false response for the if/else.
But I don't know how to write the string that goes into the script condition box.
In that case, you can create empty files with Ruby aka RGSS any version here as placeholders. It's size should always be 0 for they only exist as a filename so to say.

Ruby:
File.open("test.rvdata2", "wb") {}
That would create an empty file named test.rvdata2 there. To read it, replace "wb" with "rb" and that's it.

Ruby:
file = File.open("test.rvdata2", "rb")

Use file if you need a local variable in that very same method or @file if you need to check a couple of things from other methods before closing that file.

Then you can call file.size == 0 to identify if it's a placeholder, the rest would be actual save files.

At the end use file.close to close that specific file.
Here is a more concise explaination of my intended usage:

So, take this folder for example. It has 20 files in it. 19 of them are placeholders (each 4.42 kb). Except file #10. File #10 is an actual file with information in it.

I am trying to run a conditional branch where a file is checked against a size to return true or false. Lets say 20 kbs.
So files 1-9 and 11-20 should all return as 'false' but file 10 would return as 'true'.

example.png


I know that if I enter the filepath into a variable
File.exists?($game_variables[2707]) tells me if the file exists or not.

$game_variables[2707] = "C:\examplepath\010.mp4"
would return true, while
$game_variables[2707] = "C:\examplepath\021.mp4"
would return false because there is no 21st file in the folder.

So based on this functionallity of RPG Maker being able to read and detect files, I was wondering if it can read file size (or length, etc) any information I can use and place into a conditional string to have the conditional branch differentiate between the placeholder files and the real files.
Could you please read what I had told you a while ago?
You can do it with empty files. It just happens that you need to make Ruby create a file with an mp4 extension. You don't need them to be actual mp4 files at all. Then you can run your test and find that 010.mp4 is an actual file.

Here are the new instructions.

Make sure that game variable holds a string with a filename and a mp4 extension.

This will require the use of interpolation to make sure you can search as many files as needed.
The string stored in your game variable should look like this: "%3d.mp4"

Later on you need to call:
Ruby:
filename = sprintf($game_variables[VariableID])

Then you do what I've told you before, this time passing filename as the first parameter.
I don't understand exactly how to input it. This is what I tried to test it.
Crashes after 'Now checking actual file'

first try.png
Your problem is that the script command is sandboxed. upon closing the script command, all its data is deleted.

so the data for the file is only accessable until the script box is closed. The file and its data no longer exists on the conditional branch.

you would have to place the entire check as script code into a single script box for that to work.
Oh. That makes sense.

I'm still not sure the exact way to write the script for that but I understand the concept of what you are saying.
The Script Event Command is PARTIALLY sandboxed.
This is what I mean, local variables disappear as soon as that command has been executed.
YET, @instance variables persist even after that command has ended.
Once you no longer need the @instance variable, set it to nil.

Ruby:
@instance = nil

That's the reason why you can see @ at symbols at the beginning of every line.

Original thread: https://forums.rpgmakerweb.com/threads/using-file-size-as-a-conditional-branch.158427/