%O parameter doesn't quote filenames with spaces
Moderators: Hacker, petermad, Stefan2, white
%O parameter doesn't quote filenames with spaces
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?
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?
Re: %O parameter doesn't quote filenames with spaces
WrongRekrul 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

%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

Because contrary to you programs cant thinkRekrul wrote: 2024-01-23, 12:32 UTC Yes, you can avoid this by enclosing %O in quotes yourself, but why do you have to?

Hoecker sie sind raus!
Re: %O parameter doesn't quote filenames with spaces
"new text %O new text.%E"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?
Need more explanations?

Overquoting is evil! 👎
- ghisler(Author)
- Site Admin
- Posts: 50824
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: %O parameter doesn't quote filenames with spaces
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.
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
https://www.ghisler.com
Re: %O parameter doesn't quote filenames with spaces
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
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
Re: %O parameter doesn't quote filenames with spaces
You mean virtually every Windows program in existence?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
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?
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..."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.
Re: %O parameter doesn't quote filenames with spaces
I agree that this piece of information should be available in the TC help. Support++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?
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Re: %O parameter doesn't quote filenames with spaces
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:ghisler(Author) wrote: 2024-01-23, 14:26 UTC Quotes are added for %N, %P%%N, %T, %T%M and a few others.
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)
Code: Select all
%X%Y%P%S%T%R
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
Code: Select all
"%X%Y%P%S%T%R" or %X%Y"%P%S%T%R" or %X%Y"%P%S%""T%R" etc.
Code: Select all
'%X%Y%P%S%T%R'
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
Re: %O parameter doesn't quote filenames with spaces
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.
Re: %O parameter doesn't quote filenames with spaces
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
\"%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:
'%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
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'
Code: Select all
UpdateFolderModifiedDate-test2.ps1 "f:\_Downloads\TotalCommander\TweakTC" "f:\_Downloads\TotalCommander\DiskInternals (FileSystemsReader)" "f:\_Downloads\TotalCommander\Scripts"
Re: %O parameter doesn't quote filenames with spaces
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)
%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)
Re: %O parameter doesn't quote filenames with spaces
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:
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:
My script arises the following error:
Parameters - '%X%Y%P%S%T%R' (enclosed in single quotes)
Echoargs result:
My script result is completely successful:
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.
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 ""
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)>
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
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)'>
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)
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.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)
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.
Re: %O parameter doesn't quote filenames with spaces
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
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
Re: %O parameter doesn't quote filenames with spaces
As you can see from my previous post, this is not entirely true regarding these parameters.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
...