Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: OS X troubleshooting help needed - parse filename & open file

by elef (Friar)
on Oct 17, 2010 at 15:22 UTC ( #865811=note: print w/replies, xml ) Need Help??


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

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.
  • Comment on Re^2: OS X troubleshooting help needed - parse filename & open file
  • Download Code

Replies are listed 'Best First'.
Re^3: OS X troubleshooting help needed - parse filename & open file
by luis.roca (Deacon) on Oct 17, 2010 at 18:32 UTC
    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.
        Getting rid of the trailing space seemed to work.
        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: OK, file found -------------------------------------------- Test 2, checking if file can be opened: OK, file opened successfully. Press enter to quit
        "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://865811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-09-30 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?