S
S
Sergey Karbivnichy2020-01-30 19:36:05
linux
Sergey Karbivnichy, 2020-01-30 19:36:05

What algorithm is used to create a folder if the folder exists?

I use Linux Mint with xfce4. If you press "right click" - "Create directory" and there is already a folder with the same name in the current directory, a dialog box appears:
5e3302c4ebdc7276783779.png
which is very annoying.
I downloaded the Thunar sources and found places in the code where the right click occurs, various checks when creating a directory, and the creation of a directory itself. I played around with the code a bit, my edits work (how cool it is when the code is open!). I want to change the Thunar code so that if the "New directory" directory exists, "New directory (1)" is created, etc., as it is done in windows:
5e33046c2f28c176829833.png
I just can't figure out how to implement it. Who can give an algorithm, or an example in C, or an example in pseudocode. Thank you.
PS: I'm downloading the ReactOS sources, I'll try to look there...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-01-30
@hottabxp

What is there to invent?
If the name exists, add (i). Check if the new name exists - increment i and append to the primary name. And so on until it stops (something that needs to be foreseen)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question