quote:
Originally posted by Danny22
Sorry but that is not completely correct.
A file does not have to have an extension (.xxx).
lastIndexOf() will return -1 if there is no period in the string.
This leaves us with substring(0, -1), which will return "".
In general, this is correct.
However, the populateDp() function in the script already checks that only files with a jpg, gif, bmp or png extension are added to the array. So in this case you won't encounter filenames without an extension.
quote:
If I should further explain why I wrote the code that way, I will do so...
The reason why I used a new function, is to seperate your custom code from the original code as much as possible. It is easier for you to make changes that way.
You can of course use fileName.Name instead, because it does not really matter which one you use in this case.
However, by using fileName.Path, you can use both the full path (NewFileName) and just the name (tempFileName) in your own code without making any changes if you somehow want to do something with both.
Again, correct, but only IF you want to do something with the path. If not, it's basically a waste of CPU cycles (not that you'd notice it on most modern systems). The topic starter just wanted to get rid of the full path, so why get the full path and cut the folders off if you can get the filename with another method?
Also, if you want the path afterwards for another reason, there's still the File Object (fileName) to get the full path from in the way you did.
quote:
I like clean and reliable code.
To make it extra clean, you could even put your own code in new files if there is a lot of code.
I have to say, I like clean code too.
I just don't really see how it's cleaner to add an extra function if everything that function does can be done in a single statement too.
quote:
Please correct me if I am mistaken about anything.
It's not that you're mistaken about anything, for all I know your code works ok (haven't tested though). It's just that we seem to have a different idea on code organizing and efficiency.