Sep-27-2022, 07:55 PM
So i have a directory where im placing files after my script runs, each file currently has a unique number in the file name.
Example: igMess_'+ fileNumber+'_.csv'
Currently i have the script hardcoded with the fileNumber variable set manually before running the script, its ok now because the directory only has about 10 files, so visually easy to see what the next number would be...
What i would like to do is have a way to look in the directory for ONLY files that follow that naming convention and then determine the last/highest number so that my variable can be dynamic and use the next seq. number.
Ive seen examples of using max(), but that doesnt seem to do what i thought it would, or at least not using it correctly.
If my directory has the following files:
igMess_1_.csv
igMess_2_.csv
igMess_3_.csv
igMess_4_.csv
igMess_5_.csv
igMess_6_.csv
temp1.txt
temp2.txt
mydata.xlsx
i would like to ONLY consider the files that start with "igMess_" and end with "_.csv" and in the above example, the number i would like returned back would be "7" since that is the next seq number, so when my script runs, it names the new file as "igMess_7_.csv"
would i still use max() in some way, or do i need to using something else?
Example: igMess_'+ fileNumber+'_.csv'
Currently i have the script hardcoded with the fileNumber variable set manually before running the script, its ok now because the directory only has about 10 files, so visually easy to see what the next number would be...
What i would like to do is have a way to look in the directory for ONLY files that follow that naming convention and then determine the last/highest number so that my variable can be dynamic and use the next seq. number.
Ive seen examples of using max(), but that doesnt seem to do what i thought it would, or at least not using it correctly.
If my directory has the following files:
igMess_1_.csv
igMess_2_.csv
igMess_3_.csv
igMess_4_.csv
igMess_5_.csv
igMess_6_.csv
temp1.txt
temp2.txt
mydata.xlsx
i would like to ONLY consider the files that start with "igMess_" and end with "_.csv" and in the above example, the number i would like returned back would be "7" since that is the next seq number, so when my script runs, it names the new file as "igMess_7_.csv"
would i still use max() in some way, or do i need to using something else?