Code:# Create your string first
my_filepath_string = "Tmp/%d/something.data"
This is how editable strings are declared in the Vocab module so you can use that as a reference. Using %d in a string means that when you use sprintf ruby replace that with an integer. If you want to have total control over leading zeros in that file path you can add a number starting with 0 between % and d.
Code:my_filepath_string = "Tmp/%05d/something.data"
What happens when you use sprintf is that %05d becomes a 5 digit number with leading zeros used to fill missing digits.
Example:
6 -> 00006
153 -> 00153
2445 -> 02445
This way you know exactly how many leading zeros are there.
What is left is just to use sprintf.
Code:my_filepath_string = "Tmp/%05d/something.data"
real_filepath_string = sprintf(my_filepath_string, $game_variables[id_goes_here])
If you have doubts about how sprintf works in ruby you can
check the documentation.
In this example I used a variable to store the original path string. When you use it in your code it is much better if you change my_filepath_string to be a constant to avoid editing it by accident.
Code:MY_FILEPATH_STRING = "Tmp/%05d/something.data"
real_filepath_string = sprintf(MY_FILEPATH_STRING, $game_variables[id_goes_here])
File.file?(real_filepath_string)
# since sprintf returns the new string you should be able to use it this way as well
MY_FILEPATH_STRING = "Tmp/%05d/something.data"
File.file?(sprintf(MY_FILEPATH_STRING, $game_variables[id_goes_here]))
I recommend using the 1st way so that if you ever need the new file path string to interact with the file later you can use it without having to use sprintf again (it takes more time than just calling a variable). Since File.file? only checks existence I suppose you will actually need it later.