http://qs1969.pair.com?node_id=865810


in reply to OS X troubleshooting help needed - parse filename & open file

I'm downloading it to test it right now - you should know, however, that I installed a case-sensitive filesystem, so my results may not be the norm.

I'm on OSX 10.6.4

for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";

Replies are listed 'Best First'.
Re^2: OS X troubleshooting help needed - parse filename & open file
by elef (Friar) on Oct 17, 2010 at 15:22 UTC
    Thank you.
    As a first step, could you run the test script posted here?
    If that fails, we know there is something fundamentally wrong with what I'm trying to do.
    If the tests in the test script pass but the main script in the mediafire package still can't find the files, we'll have to start looking for some other error source.
    I think I have if ($ext eq "pdf") {...} somewhere in the script and that's why I lowercased the extension - I thought the case didn't matter anyway. This would be trivially easy to fix, and I don't think it could cause a problem here. If you test it with files that have a lower-case extension to begin with, then it's a non-issue, and in any case the test condition is (-e "$folder/$file1"), not (-e "$folder/${f1}.$ext") - so it shouldn't matter. The the string stored in $file1 isn't lower-cased.
      Hi elef, Just ran your test script and the results are below:
      Drag and drop a file here: /Users/macuser/Desktop/untitled.txt Filepath with quotes and spaces stripped: >/Users/macuser/Desktop/unti +tled.txt < -------------------------------------------- Test 1: no parsing, just checking if file is found: ERROR: file not found -------------------------------------------- Test 2, checking if file can be opened: Can't open file: No such file or directory at /private/var/folders/ce/ +ceU3CVgiEbO3AiWqVsJpqU+++TI/Cleanup At Startup/untitled text-30903276 +1.079 line 20, <STDIN> line 1. logout [Process completed]
      "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote
        Thanks for running the test. One issue I can see is that the final space wasn't stripped and it could perhaps be the reason both tests failed. Could you run it again and delete the space before pressing enter?
        Of course the regex should take care of this for the user. If I remember correctly, I did try something like this at some point: $inputfile =~ s/^ *[\"\']?(.*?)[\"\']? *$/$1/;
        Note the ? for non-greedy matching and the $ anchor, which were intended to exclude any final quotes and spaces from the match while allowing spaces inside the file name or path. I think it didn't work: trailing quotes got caught by the (.*?) and not the \"\'? despite non-greedyness. Right now I'm blanking on what the right regex is for stripping all leading and trailing spaces and quotes. There may be no spaces and no quotes, or both, or only spaces, or only quotes. Makes my head hurt.
        In fact, this may be the source of the whole problem: if there are no quotes, the script doesn't strip trailing spaces. As XP always adds quotes, this issue didn't arise on my own machine.

        Note: I noticed Your Mother's post with much the same content as I was about to finish this post. One issue is that there is no way of telling if a filename contained a leading or trailing space or the OS tacked it on, although it's pretty safe to assume it's the latter (extensions don't end in a space and file paths don't start with a space... I hope). It's another reason why people shouldn't tempt fate with ludicrous file and folder names.

        Admittedly, the method I'm using here is pretty crude: it will probably fail if the file is in the root of the drive or if it has no file extension. Again, these are fringe cases that are really low on my priority list.
        I should note that this is a hobby project; I have no obligation to accommodate people with poor file-naming habits.
Re^2: OS X troubleshooting help needed - parse filename & open file
by elef (Friar) on Oct 17, 2010 at 20:50 UTC
    As you can see, this got cleared up in the meantime. To make absolutely sure that this is indeed the issue, could you run the script in the zip package anyway?
    Just delete any leading and trailing spaces manually after dropping in the files and see if you get an error message.
    Thank you.

    Edit: this was of course addressed to pobocks who said he downloaded the package to test it. The peculiar perlmonks answer system placed it here.

      Done and works.

      for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
        Thank you.