Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

handling special characters in folder/file names

- - - - -

  • Please log in to reply
10 replies to this topic

#1
radix

radix

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 743 posts
  • Joined 08-February 07
  • OS:Windows 8 x64
  • Country: Country Flag

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, 21 January 2015 - 01:41 PM.



How to remove advertisement from MSFN

#2
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Remove the & characters then!

 

The folder/file names are your choice so choose something sensible for the environment and scripting language you're using.



#3
radix

radix

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 743 posts
  • Joined 08-February 07
  • OS:Windows 8 x64
  • Country: Country Flag

So, these are the limit of batch scripting. Thanks!



#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,438 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Perhaps a VBS script might work, place the below script in the folder and it should open Test.txt if it there.
Attached File  SpecailCharaterVBS.png   59.39KB   3 downloads
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.


GunSmokingMan



#5
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,005 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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.robvander...escapechars.php

 

@gunsmokingman

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

 

jaclaz


  • radix likes this

#6
radix

radix

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 743 posts
  • Joined 08-February 07
  • OS:Windows 8 x64
  • Country: Country Flag

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, 22 January 2015 - 10:30 AM.


#7
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,587 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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"


#8
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,438 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Well Jaclas my script will run with special charaters in the name.

Attached Files




GunSmokingMan



#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,005 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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.ntlw...oolishness.html

 

jaclaz



#10
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,870 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag

@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.ntlw...oolishness.html.

 

Cheers and Regards


Posted Image


#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 15,005 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

@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.ntlw...oolishness.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.ntlw...ynepollard/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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users