From: forgottenwizard Date: 2007-10-28T03:57:18+09:00 Subject: Re: Problem using FileUtils to sort JPEG files On 07:33 Sat 27 Oct , 7stud -- wrote: > > It makes a > > bit more sense to me to check to make sure the dir exist > > while looking through everything > > Consider this: how does ruby determine if a filename is a directory? > Suppose your directory has 2,000 files in it. Next, suppose you ask > ruby if "my_file.jpg" is a directory. What if ruby first has to look at > each and every one of those 2,000 files to look for a match with > filename? Then if it found a match, ruby had to look at the stats for > the file to determine if it's a directory. That would mean that every > time you ask if a filename is a directory, ruby has to step through > every one of those 2,000 files to look for a match. Do you think that > is very efficient? The way I'm currently going through all this, and the cases I'm trying to keep from running across (such as a jpg named myfile), what it seems to me you are suggesting is going through and check every single file to make sure there isn't a new format, and if there is, make a new directory, THEN go back though the same directory, find the format AGAIN, then sort through everything. It makes more sense to me to go through and do both at once, since (correct me if I am wrong here) it takes longer to find the file format as opposed to, say, seeing if there is a directory with the same name as that format. > > > > I added in the rescue > > block the same as you have, and it still exists the loop when run over > > the script itself. > > > > I have no idea what that means. If you are asking how to determine what > error to catch with the rescue statement, do this: remove the rescue > statement from your code and try to read a file that RMagick doesn't > recognize, and then examine the error message. The error message will > give the name of the error. For instance, if you run this program: > > puts x > > the error message is: > > "undefined local variable or method `x' for main:Object (NameError)" > > To handle that error, you can write: > > begin > puts x > rescue NameError > puts "caught the error" > end I'll look more into that. It seems a bad filetype causes several errors, so I'm having to go through and take care of each of them.