Hey
how can i save a file to the system but if the file name already exists then add “_” or try another name?
- i dont want to overwrite another file.
- i must save the new file.
Hey
how can i save a file to the system but if the file name already exists then add “_” or try another name?
You may just change the letter register.
For example: File.html and file.html - will be downloaded as two different files.
Regards,
Marina
im saving a lot of files on the directory. and I’m giving them a random name like this currently
so my question is: how can i be sure the file will be saved even if there is by chance another file already exists? and not overwrite the old one.
After choosing overwrite file: false
the new file will not overwrite the old one.
Regards,
Marina
But if by chance the file name already exists, the new file will not be saved.
I don’t want that to happen.
Hello @mohammad_altoiher
It is a good question.
If you use overwrite file: false
you will receive an error you should catch it and try one more time with a new file name.
that’s what i was doing but it still need to recheck if the new name also exist.
i think it will be easier if that was a simple true or false in the Create file block. so it will take care of the file name and make sure it will be saved even if the name is already there.
i don’t care what the file name. im getting the url and that what count.
it will save alot of headache for other users im sure
Here’s a sample logic that checks if the file exists. You can put it into a reusable function which will become a block on its own:
And i have to wrap that in a loop right?
I do not know, it depends on what your logic needs to do. The logic I shared is for a single file. Since you can upload only one file at a time, I do not see how and why a loop would be needed here, but again, it depends on what your app does.
the reason for the loop is to keep checking for the file name.
if i check one time then there is already a file with that name i will have to try another name and recheck until there is no file with such name.
Sure, it makes sense in that case. Btw, to make file names more unique, you can add the current timestamp to the name of the file…
Thats an excellent solution combined with the user-id
Thanks mark