%O parameter doesn't quote filenames with spaces

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: Hacker, petermad, Stefan2, white

Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

%O parameter doesn't quote filenames with spaces

Post by *Rekrul »

Well, this certainly seems like a bug, and I couldn't find anything about in the documentation, but I'll probably be told that it's working the way it was intended...

The help files says that the parameter %N inserts the selected filename, and that %O inserts the selected filename without the extension.

Let's say that you have a file called My Book Report.txt

%N = "My Book Report.txt"

%O = My

Yes, you can avoid this by enclosing %O in quotes yourself, but why do you have to?

If this is the intended behavior, can someone please describe to me a scenario where you would only want the first word of a filename containing spaces that isn't a completely obscure and unique one-off case?
User avatar
Sir_SiLvA
Power Member
Power Member
Posts: 3381
Joined: 2003-05-06, 11:46 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *Sir_SiLvA »

Rekrul wrote: 2024-01-23, 12:32 UTC Let's say that you have a file called My Book Report.txt

%N = "My Book Report.txt"

%O = My
Wrong :!:
%O = My Book Report

You just have a default behaviour that another program that gets My Book Report split it by spaces if you dont use quotes :!:
Rekrul wrote: 2024-01-23, 12:32 UTC Yes, you can avoid this by enclosing %O in quotes yourself, but why do you have to?
Because contrary to you programs cant think :D
Hoecker sie sind raus!
Fla$her
Power Member
Power Member
Posts: 3015
Joined: 2020-01-18, 04:03 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *Fla$her »

Rekrul wrote: 2024-01-23, 12:32 UTC Yes, you can avoid this by enclosing %O in quotes yourself, but why do you have to?
"new text %O new text.%E"
Need more explanations? :)
Overquoting is evil! 👎
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50824
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: %O parameter doesn't quote filenames with spaces

Post by *ghisler(Author) »

TC does not add quotes around most parameters like %O because they are often combined with others, e.g. the user could write %O_copy.%E or so.
Quotes are added for %N, %P%%N, %T, %T%M and a few others. User %Q at the start to turn off automatic quotes.
Currently it's not planned to add automatic quotes to more placeholders, sorry.
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16099
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %O parameter doesn't quote filenames with spaces

Post by *petermad »

Moderator message from: petermad » 2024-01-23, 19:24 UTC

Moved to "TC Behaviour which will not be changed" from "TC11.x bug reports (English)"
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Rekrul
Junior Member
Junior Member
Posts: 69
Joined: 2007-11-04, 21:40 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *Rekrul »

Sir_SiLvA wrote: 2024-01-23, 13:36 UTC Wrong :!:
%O = My Book Report

You just have a default behaviour that another program that gets My Book Report split it by spaces if you dont use quotes :!:
You mean virtually every Windows program in existence?

While there may be some programs that will accept a filename with spaces in it that isn't quoted, the vast majority will interpret space as a delimiter and stop reading a filename there. Can you name a common Windows program that accepts filenames on the command line, which doesn't need filenames with spaces to be enclosed in quotes?
ghisler(Author) wrote: 2024-01-23, 14:26 UTC TC does not add quotes around most parameters like %O because they are often combined with others, e.g. the user could write %O_copy.%E or so.
Quotes are added for %N, %P%%N, %T, %T%M and a few others. User %Q at the start to turn off automatic quotes.
Currently it's not planned to add automatic quotes to more placeholders, sorry.
Thank you for the explanation. May I respectfully suggest that the help file should make it clear which parameters will be enclosed in quotes and which won't be? I'm not suggesting that it be stated in the description for each and every parameter, maybe just a note at the top like "Please note, only the following parameters will be enclosed in quotes if they contains spaces, all others you will have to enclose in quotes yourself: %N, %P%N, %T, %T%M..."
User avatar
Dalai
Power Member
Power Member
Posts: 10016
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: %O parameter doesn't quote filenames with spaces

Post by *Dalai »

Rekrul wrote: 2024-01-24, 00:37 UTCMay I respectfully suggest that the help file should make it clear which parameters will be enclosed in quotes and which won't be?
I agree that this piece of information should be available in the TC help. Support++
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
iG0R
Junior Member
Junior Member
Posts: 58
Joined: 2018-10-05, 16:16 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *iG0R »

ghisler(Author) wrote: 2024-01-23, 14:26 UTC Quotes are added for %N, %P%%N, %T, %T%M and a few others.
Could you please clarify which parameters or something else I need to add so that each argument passed is enclosed in quotation marks in the following situation:
I have a PowerShell script that takes multiple folder paths as arguments. The folder names may contain spaces and words that resemble cmdlets, that is why they need to be enclosed in quotes.
For example, when I pass the following folder as an argument:

Code: Select all

f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
and use the following parameters:

Code: Select all

%X%Y%P%S%T%R
i get the following error:

Code: Select all

FileSystemsReader : The term 'FileSystemsReader' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:117
+ ... t2.ps1 f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
+                                                        ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (FileSystemsReader:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
No matter where in the parameters I put quotation marks to enclose the folder names, they are never enclosed in them when passed to the script as arguments. For example:

Code: Select all

"%X%Y%P%S%T%R" or %X%Y"%P%S%T%R" or %X%Y"%P%S%""T%R" etc.
But I found a workaround for this situation and enclosed the parameters in single quotes:

Code: Select all

'%X%Y%P%S%T%R'
Now it works and with such folder names as well:

Code: Select all

f:\_Downloads\TotalCommander\PlugIns\UpdateFolderModifiedDate-test2.ps1 'f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)'

Arguments         : f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)

RootFolders from arguments:
- f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
RootFolders from arguments: f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
Processing folder: f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
1.  = Get-ChildItem -Path f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader) -Directory
2.
5. Update-ParentFolderTime -folderPath f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
7. The folder 'f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)' has the most recent LastWriteTime than its child files and subfolders
However, to ensure the script functions correctly even when multiple folder names are passed as arguments, it was necessary to complicate argument handling within the script itself. Which would have been much easier if TC had enclosed each folder name in quotation marks.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: %O parameter doesn't quote filenames with spaces

Post by *Stefan2 »

iG0R wrote: 2024-08-15, 12:53 UTC

See, always the outer quotation marks are (mostly) "eaten" by the different interpreters of scripts or tools (as here with TC + script engine)
To work with PowerShell from within TC, tripple (""") or escape (\") the double quotation marks.
If PS doesn't have to resolve the string or the $variable, you can also use single (') quotation marks.
As for TC 'var' is the same as "var".


So if you use in TC smtg like
"%X%Y%P%S%T%R"
PS only gets (or sees)
%X%Y%P%S%T%R
(expanded, of course)


Instead try """
"""%X%Y%P%S%T%R"""
or \"
\"%X%Y%P%S%T%R\"
or '
'%X%Y%P%S%T%R'
in TC to provide parameters to PS.




 
iG0R
Junior Member
Junior Member
Posts: 58
Joined: 2018-10-05, 16:16 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *iG0R »

Stefan2 wrote: 2024-08-15, 14:07 UTC
Thanks for the clarification and for sharing your knowledge.
But I have already tried the options with triple or escape quotes, but without success.
When I used triple quotes
"""%X%Y%P%S%T%R"""
I got the following error:

Code: Select all

The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
And after using escape quotes
\"%X%Y%P%S%T%R\"
the following:

Code: Select all

Script was run with the following command:
f:\_Downloads\TotalCommander\PlugIns\UpdateFolderModifiedDate-test2.ps1 \
Arguments         : \
RootFolders from arguments:
Although the whole command should be the same as when I use parameters enclosed in single quotes
'%X%Y%P%S%T%R'
after which I get the following proper work of the script:

Code: Select all

Script was run with the following command:
f:\_Downloads\TotalCommander\PlugIns\UpdateFolderModifiedDate-test2.ps1 'f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader) f:\_Downloads\TotalCommander\Scripts'

Arguments         : f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader) f:\_Downloads\TotalCommander\Scripts

RootFolders from arguments:
- f:\_Downloads\TotalCommander\TweakTC
- f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
- f:\_Downloads\TotalCommander\Scripts
RootFolders from arguments: f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader) f:\_Downloads\TotalCommander\Scripts
Processing folder: f:\_Downloads\TotalCommander\TweakTC
What parameters should I use in TC so that not all arguments are enclosed in single quotes, but each of them is enclosed in double quotes?
I.e. what I get now:

Code: Select all

UpdateFolderModifiedDate-test2.ps1 'f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader) f:\_Downloads\TotalCommander\Scripts'
what I want to get:

Code: Select all

UpdateFolderModifiedDate-test2.ps1 "f:\_Downloads\TotalCommander\TweakTC" "f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)" "f:\_Downloads\TotalCommander\Scripts"
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: %O parameter doesn't quote filenames with spaces

Post by *Stefan2 »

Please note also the help:

%R --- like %S, but with selected names from the target panel
%S --- insert the names of all selected files into the command line. Names containing spaces will be surrounded by double quotes.


So you may end with something like: xxxxx "my file.ext"" and sometimes with: xxxxx myFile.exe"

Use a tool like Echoargs or similar to check your command line:
Echoargs.exe is a simple tool that spits out the arguments it receives.
It is part of the PowerShell Community Extensions download, http://pscx.codeplex.com/ (( https://codeplexarchive.org/project/Pscx ))



So often it is better to pass the arguments to an script and handle there the quotes yourself (remove every quoting and add correct quotes yourself)





 
iG0R
Junior Member
Junior Member
Posts: 58
Joined: 2018-10-05, 16:16 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *iG0R »

Thanks again.
I read everything about the parameters in the help (F1 -> Operation -> Menus -> Menu Configuration -> Change button bar).
That is why I use the %S and %R parameters in combination with %P and %T, despite the fact that I only need paths as arguments for my script.
But even with this configuration of parameters, none of the arguments are surrounded by double quotes.

Concerning echoargs.exe
I tested it and it gives a completely different result than my script sees it.
To find out how my script handles arguments, I inserted the following code at the beginning of the script:

Code: Select all

# Print the full command line used to run the script
Write-Host "Script was run with the following command:"
Write-Host $MyInvocation.Line
Write-Host ""
And after each command there is an explanatory text-debugging code in the form of a Write-Host command with the corresponding text.

For example:
Parameters - %X%Y%P%S%T%R (i.e. without any quotation marks)
Echoargs result:

Code: Select all

Arg 0 is <f:\_Downloads\TotalCommander\TweakTC>
Arg 1 is <f:\_Downloads\TotalCommander\Ultimate File Manager>
Arg 2 is <f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)>
My script arises the following error:

Code: Select all

FileSystemsReader : The term 'FileSystemsReader' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:205
+ ... anager f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
+                                                        ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (FileSystemsReader:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Parameters - '%X%Y%P%S%T%R' (enclosed in single quotes)
Echoargs result:

Code: Select all

Arg 0 is <'f:\_Downloads\TotalCommander\TweakTC>
Arg 1 is <f:\_Downloads\TotalCommander\Ultimate File Manager>
Arg 2 is <f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)'>
My script result is completely successful:

Code: Select all

Script was run with the following command:
f:\_Downloads\TotalCommander\PlugIns\UpdateFolderModifiedDate-test2.ps1 'f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\Ultimate File Manager f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)'

Arguments         : f:\_Downloads\TotalCommander\TweakTC f:\_Downloads\TotalCommander\Ultimate File Manager f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)

RootFolders from arguments:
- f:\_Downloads\TotalCommander\TweakTC
- f:\_Downloads\TotalCommander\Ultimate File Manager
- f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)
Stefan2 wrote: 2024-08-15, 18:41 UTC So often it is better to pass the arguments to an script and handle there the quotes yourself (remove every quoting and add correct quotes yourself)
I would be happy to process any quotation marks that would enclose arguments, the keyword, individually, i.e. each argument is surrounded by its own quotation marks.
But that's the point, and that's why I came to this topic, because the TС doesn't allow me to do that. It only allows to surround all the arguments at once with quotes, and even then, only single quotes.
User avatar
petermad
Power Member
Power Member
Posts: 16099
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %O parameter doesn't quote filenames with spaces

Post by *petermad »

Dalai wrote: 2024-01-24, 11:17 UTC
Rekrul wrote: 2024-01-24, 00:37 UTCMay I respectfully suggest that the help file should make it clear which parameters will be enclosed in quotes and which won't be?
I agree that this piece of information should be available in the TC help. Support++
Until it gets into the help - here are the parameters and combinations that i find to be automatically quoted when containing spaces:
%N
%P%N
%P%M
%T%N
%T%M
%S
%S1-%Sn
%R
%R1-%Rn
%P%S
%P%S1-%Sn
%P%R
%P%R1-%Rn
%T%S
%T%S1-%Sn
%T%R
%T%R1-%Rn
%C
%C1-%C9
%V
%v

Substrings are also quoted if the non-substring parameter would be quoted: %N:~0,-1 is quoted, but %P:~0,-1 and %P:~0,-1%N are not quoted.

Notice that even though %N is automatically quoted %M is not, which I find highly inconsistent - https://www.ghisler.ch/board/viewtopic.php?t=76443

Maybe it is easier to remember which parameters are not automatically quoted:
%O, %E and %M
Standalone %P and %T,
%B (and derivatives of %B)
License #524 (1994)
Danish Total Commander Translator
TC 11.55rc4 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1393a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
iG0R
Junior Member
Junior Member
Posts: 58
Joined: 2018-10-05, 16:16 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *iG0R »

petermad wrote: 2024-08-16, 16:40 UTC Until it gets into the help - here are the parameters and combinations that i find to be automatically quoted when containing spaces:
...
%P%S
...
%T%R
...
As you can see from my previous post, this is not entirely true regarding these parameters.
JOUBE
Power Member
Power Member
Posts: 1685
Joined: 2004-07-08, 08:58 UTC

Re: %O parameter doesn't quote filenames with spaces

Post by *JOUBE »

Dalai wrote: 2024-01-24, 11:17 UTC
Rekrul wrote: 2024-01-24, 00:37 UTCMay I respectfully suggest that the help file should make it clear which parameters will be enclosed in quotes and which won't be?
I agree that this piece of information should be available in the TC help. Support++
Support++
Post Reply