0

I am currently writing an input file renamer, to ensure that all my input values have an unique name. However I am now wondering how to store the unique name, most likely being an integer + extension.

I have considered this so far:

  • Database. Might be slow, always needs a connection up.
  • Registry. Not sure if you would want to use registry for a simple counter like this, which will be modified a lot.
  • Plain text file. Seems like most simple option, but is prone to easy deletion, hence does not offer that much 'security' as database/registry.

The renamer will act like this:

  • Input randomstrings.pdf -> 1.pdf
  • Input notrandomatall.pdf -> 2.pdf
  • Input abcdef.pdf -> 3.pdf
  • etc.

It needs to be persistent over multiple executions of the program and system (server) shutdown/failure aswell.

Regards

2 Answers 2

1

This answer already given:

  1. Databases can handle querying tasks, so you don't have to walk over file manually. Databases can handle very complicated queries.

  2. Databases can handle indexing tasks, so if tasks like get record with id = x can be VERY fast

  3. Databases can handle multiprocess/multithread access.

  4. Databases can handle access from network

  5. Databases can watch for data integrity

  6. Databases can update data easily (see 1) )

  7. Databases are reliable

  8. Databases can handle transactions and concurrent access

  9. Databases + ORMs let you manipulate data in very programmer friendly.

Sign up to request clarification or add additional context in comments.

Comments

1

The classic suggestion is just to generate a random sequence of characters (6 alphanumeric usually suffices), and just try a different filename if the target filename already exists. After all, the filesystem does already store information about the used filenames, so there's really no need to store that information again in some other form (database, registry, etc.).

4 Comments

The files move to different folders and subfolders though, so I do not always know where they are. However there is a to-be-checked list in my database, which absolutely may not have duplicate filenames. So I cannot simply check if a file already exists.
So you already have a database? Why not use that if you need to hit the database anyway?
It is definately a possibility. But I was asking about the best-practice in the OP. A downside though is that no input files can be processed anymore if the database/connection is down.
Couldn't you pull a list of to-be-checked into a set or a map from the database (or wherever)? Then serialize it however you want, and let the contract for map and set take care of all that uniqueness business? Or am I misunderstanding your needs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.