Author Topic: Openning folder for viewing using path as command line parameter  (Read 189 times)

Offline user_223456

  • Newcomer
  • *
  • Posts: 2
    • View Profile
I'm using Total Commander's toolbar buttons to open programs with path as command line parameter.
Unfortunately Total Commander is adding trailing slash to path variable and it's not accepted by Photo Mechanic.

This works:
Code: [Select]
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\photos"
but this not
Code: [Select]
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\photos\"
Not really Photo Mechanic problem, but it would be great when PM accepts folder path with trailing slash.

BTW. Just tested PM2025.7955 with 1000 Canon R5 RAWs in RAM drive. It's lightning fast. Preview is instant!

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25224
    • View Profile
    • Camera Bits, Inc.
Re: Openning folder for viewing using path as command line parameter
« Reply #1 on: April 14, 2025, 12:10:57 PM »
I downloaded and installed Total Commander.  I created a custom toolbar button that runs Photo Mechanic.  I used %P for the parameter.

I'm finding that if I use the left side window (source column?) pane and I navigate into a folder containing pictures and then click the button I made, then PM launches and shows the photos.  If I have a folder selected and click the custom button, I'm seeing PM open the parent folder of the folder I selected.

What does your custom button look like (take a screenshot in JPEG format and post it here) ?

Use the 'Attachments and other options' link when you're composing your reply to this message and there you'll be able to upload your JPEG format screenshot.

Thanks,

-Kirk

Offline user_223456

  • Newcomer
  • *
  • Posts: 2
    • View Profile
Re: Openning folder for viewing using path as command line parameter
« Reply #2 on: April 15, 2025, 06:39:30 AM »
Kirk, thx for reply.  Screenshot is not necessary... custom command button config is very simple...

Code: [Select]
Command   : "C:\Program Files\Camera Bits\Photo Mechanic All-in-One\Photo Mechanic.exe"
Parameter : %P
Icon      : "C:\Program Files\Camera Bits\Photo Mechanic All-in-One\Photo Mechanic.exe"

I'm sure Total Commander is adding trailing backslash (\) every time. Tested with batch .bat script:
Code: [Select]
echo %1
I was wrong in my post.
PM will indeed show photos in "D:\PHOTOS" when using TC with %P
PM wil NOT show photos in "D:\MY PHOTOS" when using TC with %P
The difference is a space in folder's name

Just out of curiosity I tesed PM with Windows Shortcut (LNK):
Code: [Select]
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" D:\PHOTOS          OK (no backslash, no space, no quotes)
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" D:\PHOTOS\         OK (backslash, no space, no quotes)
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\PHOTOS\"       PM EMPTY (quotes + backslash, no space), works in TC
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\PHOTOS"        OK (quotes, no space, no backslash)
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\MY PHOTOS"     OK (space + quotes,  no backslash)
"..\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\MY PHOTOS\"    PM EMPTY (space + quotes + backslash)

Tested also with batch .bat script... this does not work, PM empty
Code: [Select]
start "" "C:\Program Files\Camera Bits\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\PHOTOS\"
start "" "C:\Program Files\Camera Bits\Photo Mechanic All-in-One\Photo Mechanic.exe" "D:\MY PHOTOS\"

Before I started this discussion, I used proxy exe program I wrote myself in Delphi inserted between TC and PM:
Code: [Select]
result := '"' + SysUtils.ExcludeTrailingPathDelimiter(s) + '"';
After digging some more I found a solution in this discussion within TC author's forum
https://ghisler.ch/board/viewtopic.php?p=422278#p422278

The solution is a parameter written like that:
Code: [Select]
"%P:~0,-1"
Hope I did not take much of your time. Thanks for support and best regards.

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 25224
    • View Profile
    • Camera Bits, Inc.
Re: Openning folder for viewing using path as command line parameter
« Reply #3 on: April 15, 2025, 01:16:37 PM »
I'm glad you found a solution that works for you.  I'm responding just for completeness.  I tried most of your examples and stopped PM in a debugger to see what it receives in the various cases you gave.

When using double-quotes around a parameter, some characters are treated as 'escape' characters, including the backslash character, though in the case of the backslash character, this escaping behavior doesn't happen all the time.

Given the path: C:\My Photos\

If you use the following in TC as the parameter: "%P"

...then the parameter that PM will be given is: C:My Photos"

Note the trailing double-quote.  No folder exists with that name.  DOS has a number of idiosyncrasies, and this is one of them.

Your solution of trimming off the trailing backslash solves this problem.  Another solution would be to use the parameter:

"%P\"

The reason this works is because of how a trailing slash is treated when followed by a double-quote by command-line parsing.  The additional backslash escapes the backslash from the path that TC provides when %P is expanded.

If you use the above, then the parameter that PM will be given is: C:\My Photos\

PM, is happy to open this path, because it exists.

-Kirk