Jump to content

handling special characters in folder/file names


Recommended Posts

Hello,

I got this folder structure:

"\$1\Install\CCleaner_x86_&_x64"

 

In $1 I have Install.cmd which call a cmd file located in the above folder structure: "\$1\Install\CCleaner_x86_&_x64\CCleaner_x86_&_x64.cmd"

CCleaner_x86_&_x64.cmd will install CCleaner and it's OK.

 

Install.cmd from $1 folder have this content:

@Echo Off
:: Install CCleaner
START CMD /C "CD %~dp0Install\Piriform_CCleaner_5.1.5075_x86_&_x64 & CCleaner_x86_&_x64.cmd"

 

and don't work. If I remove & characters from folder and file names, it will work fine.

So, it's possible to succesfully call the second cmd file if it's located in a folder structure that contain & character and/or spaces?

Thanks

Edited by radix
Link to comment
Share on other sites


Perhaps a VBS script might work, place the below script in the folder and it should open Test.txt if it there.

post-5386-0-96372700-1421890364_thumb.pn

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") If Fso.FileExists("Test.txt") Then  WScript.Echo "Confirm : " & _  Replace(WScript.ScriptFullName,WScript.ScriptName,"") & "Test.txt"  CreateObject("Wscript.Shell").Run("Test.txt"),1,False Else  WScript.Echo "Missing : " & _  Replace(WScript.ScriptFullName,WScript.ScriptName,"") & "Test.txt" End If 
Contents Of Test.txt

Testing $ in pathway.

Link to comment
Share on other sites

It is not about "limits" of batch files.

 

The concept of "special" characters is that a few characters are "special" ;).

 

Which while it remains true :yes: that it makes very little sense (actually NO sense :no:) to use a "special" character in a file name as it is the perfect way to make your own batches/scripts/whatever more complex than needed and have *any* third party batch/script/whatever fail, the "special" character can be dealt with - in a "special" way ;).

Namely you need to escape "special" characters:

http://www.robvanderwoude.com/escapechars.php

 

@gunsmokingman

"$" is not AFAIK/AFAICR a "special" character in batch. :w00t:

 

jaclaz

Link to comment
Share on other sites

Thanks jaclaz to point in the right direction.

The working batch script:

START /WAIT CMD /C "CD %~dp0Install\Piriform_CCleaner_5.1.5075_x86_^&_x64 & Piriform_CCleaner_5.1.5075_x86_^&_x64.cmd"
Edited by radix
Link to comment
Share on other sites

You may in your example above, be better advised using START "" /WAIT, where "" is "EMPTY TITLE".

 

 

It's still a pointless exercise to have a file and folder structure over which you have full control and deliberately use naming structures which are not suitable.

 

The folder inside $1 you have named Install, all of the sub folders and their contained batch files can be named anything at all, so why choose something which means that you need to take special action within their contained installation scripts.

 

Take for instance the example above, everyone knows that the program is called CCleaner, nobody, except for those directly involved with the Developer cares at installation time who makes it so drop the Piriform_ from both the directory and file names. If I was to only have x64 version of any software then I would include x64 in the names otherwise I know that the software would install on either platform. So since this obviously installs on both platforms, just drop the _x86_&_x64 from the names. Additionally, the installation batch file in every folder doesn't need to carry the same name as the parent folder, if it's in the CCleaner directory it's relatively safe to assume it isn't used to install Opera in the Opera directory, so just tell us what it does by giving it a sensible name. Then you should be creating the individual batch files to use their parent directories if necessary for the current directories in order that you don't have to specifically code it in your working batch script.

 

Examples:

CALL "%~dp0Install\CCLeaner_5.1.5075\install.cmd"

START "" /W CMD /C "%~dp0Install\CCLeaner_5.1.5075\install.cmd"

 

The system above also means that if you wanted to install the following five programs you could use something like this:

FOR %%A IN ("Prog_1" "Prog_2" "Prog_3" "Prog_4" "Prog_5") DO CALL "%~dp0Install\%%~A\install.cmd"
Link to comment
Share on other sites

Well Jaclas my script will run with special charaters in the name.

I never doubted it :), I am pretty sure that your .vbs (or other) scripts are well thought out and well written :thumbup , I was only pointing out how your earlier example:

Testing $ in pathway.

was not a valid example of a test of *anything* for a "special" character in a path (because "$" is not "special").

 

Gotta go :hello: , I have to test my new scuba diving equipment and - strangely enough - I go underwater to test it, as last time I tested one by making a short (but brisk ;)) walk outside it came out eventually that it was not fully waterproof...

 

@radix

Well, you have been told (and re-told):

http://homepage.ntlworld.com./jonathan.deboynepollard/FGA/dukhat-on-foolishness.html

 

jaclaz

Link to comment
Share on other sites

@jaclaz, I believe you have an extra period "." in your link above after "com" - ntlworld.com./jonathan.  Without it, the link works fine. - http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/dukhat-on-foolishness.html.

 

Cheers and Regards

Yes/no :w00t::ph34r:

 

Meaning that yes :yes:, there is actually an "extra dot after the com" in the posted link :blushing:, which is a (recent) copy/paste from the generic DeBoyne Pollard's FGA's page:

http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/

but no :no:, the link works fine here with or without the extra dot (... like we were talking here of special characters....)

I wonder HOW I managed to insert it :unsure:

 

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...