I have about 100,000 files in a directory. I have to move all these files to another directory. There are two ways of doing it.
rename(oldfile, newfile)
link(oldfile, newfile)
unlink(oldfile)
Which approach is better? Are there any other better solutions?
Short answer:
The first solution.
Using the rename
call you only execute one system call, and it can be further optimized by the system and / or the implementation.
You also state clearly what you intend to do, which is more important than simply searching ultimate performance on a single point of your program.
The link
/unlink
solution works also, but it's really not clear what you intend to do.
Also, how do you manage the link
on multiple filesystems ? And the link is not even possible on some filesystem or operating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With