AnonymousX

[Solved] Open Folder Directory that contains commas

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm trying to create a program where the user can input a material number into a GUI and the script will search out and find the respected material folder. I've been able to piece together the file mapping part so that the correct folder is stored within a variable. However I can not seem to get the Run function to work as the directory contains commas. Could I please get assistance with this?

Here is some test code I've experimented with

$filepath = "C:\Users\annoymousx\Documents\" ; Variable Works
;$filepath = "C:\Users\annoymousx\Documents\Test with Spaces\"; Works with folder spacing
$filepath = $filepath & "Test with Spaces\"; Works with using a prior directory history
$filepath = $filepath & "Folder with ()"; Works if brackets are used

;$filepath = $filepath & "\Folder with ," ;Does not Work if comma is used in file directory
$filepath = $filepath & "\Folder with " & ""","""; Works if triple brackets are used

Run("explorer.exe " & $filepath)

 

So I've learnt if you put triple quotations around a comma it will work correctly. The challenge is, in the actual script i'm not manually entering in text.

Example:

$filepath = $filepath & $Materialclass[$classnum] & "\"

 

Which is put into a loop, then at the end of the script I have the correct file path saved to the variable but it may contain many commas. 

How would I take this variable with the correct file path and open windows explore to it?

Say if the variable contained the value: C:\Users\anonymousx\Documents\This folder has a ,\comma, (comma, comma,)\And more , here

Thanks for any suggestions,

 

Edited by AnonymousX

Share this post


Link to post
Share on other sites



Just use single/double quotes for example:

Run('Explorer.exe "' & $hFileName & '"')

 

1 person likes this

Share this post


Link to post
Share on other sites
13 hours ago, Subz said:

Just use single/double quotes for example:

Run('Explorer.exe "' & $hFileName & '"')

 

Worked like a charm! Thanks that was an easy fix for what I thought was going to be a big headache

Share this post


Link to post
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

  • Similar Content

    • MuffinMan
      By MuffinMan
      I am trying to rebuild an old single signon script that has been giving us a bit of trouble lately.  I didn't write it and it was written in another script language.  If the target program is already open it will have the current user's last name as part of the window text, which I am trying to compare against the user name to see if I should just WinActivate or Process Close and start the program over.  I will be provided the username like "jones", or "smith" and the title check works fine for last names (with no spaces), but if the last name DOES contains spaces, say "Nom De Plume", then all I will be given as a username is "nomdeplume".  Is there any way (via a regex maybe) that I can still check the text on the screen and somehow ?  I have been reading about the Advanced (4) mode of WinTitleMatchMode, but it is over my head.  Any help is appreciated.  Here is a small reproducer script:
      Opt("WinTitleMatchMode", -1) Run("Notepad") WinWait("[CLASS:Notepad]", "", 10) Send ("Smith" & @CRLF & "Jones" & @CRLF & "Nom De Plume" & @CRLF) If WinExists("[CLASS:Notepad]", "jones") Then MsgBox(0,"FOUND","Found Jones") EndIf If WinExists("[CLASS:Notepad]", "nomdeplume") Then MsgBox(0,"FOUND","Found Nom De Plume") EndIf  
    • jsmcpn
      By jsmcpn
      Hello all!  I'm trying to make a little script that sends a message over TCP.  An example payload would be:
      MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS> Note how the payload contains special characters, and how the CDATA contains a SPACE (i.e.  "Not Running")
      My compiled AU3 script expects exactly two command line arguments:
      1) destination server/port expressed as 127.0.0.1:80
      2) the payload I want to send to my server application (which may have multiple ATTRs, this example only has one ATTR)
      MyApp.exe 127.0.0.1:80 "MY_PAYLOAD#<ATTRS><ATTR><NAME>MAILSERVER</NAME><OPERATION>set_value(ServiceStatus)</OPERATION><VALUE><![CDATA["Not Running"]]></VALUE><TIMESTAMP>1349297031</TIMESTAMP></ATTR></ATTRS>"  
      My problems (plural) are with parsing of the second argument:
      1)  If I don't wrap second argument in double-quotes, then Windows bails out before even launching EXE with "< was unexpected at this time"
      2)  If I DO wrap second argument in double-quotes, then two problems can arise when my EXE parses the arguments:
                   aa) The double-quotes are stripped from the CDATA value. ["Running"] is stored in the array as [Running]
                   bb) If CDATA value DOES have a space, such as ["Not Running"], then I get an extra unwanted $CmdLine[3] because the SPACE between Not and Running is treated as a separator.  My second argument is thus split into two separate arguments, [2] and [3] instead of being treated as one arg stored in [2]
                              cc) Additionally, my script exits because it has an "IF $CmdLine[0] <>2 THEN Exit (1)" to validate the command line args.
      I've tried launching the EXE with the second argument wrapped and escaped in a multitude of ways.  Double double-quotes, triple double-quotes, single-quotes on the outside with double-quotes inside (i.e.  '"ETC"'), starting the second arg with a caret (i.e. ^"ETC") and one of three things happens:
      1) "< was unexpected at this time"
      2) my CDATA value is stripped of its double-quotes
      3) my payload argument gets split at the space in the CDATA value and the script bails out due to the unexpected 3rd argument.
       
      Any ideas?  How can I preserve the second argument literally, including all special characters, quotes and spaces?
      I tried adding some string manipulation code to grab the 2nd argument from $CmdLineRaw and it works (preserves the "Not Running" with quotes), but my number of arguments is still 3 instead of 2 if there is a space in the CDATA value.
       
      Any assistance would be greatly appreciated!
    • 31290
      By 31290
      Hi Everyone, 
      I'm facing a small issue while trying to remove spaces at the end of lines contained in a temp file.
      Indeed, I'm creating the list of uninstallable apps on my computer and display them in an edit box.
      Here's the result:

      As you can see, all lines have bunch of spaces at their end.
      I did try the StringStripWS function, the StringTrimLeft one... no one works... 
      Here's the code I use:
      Func f_ListApps() GuiCtrlSetState ($g_AppList, $GUI_DISABLE) RunWait(@ComSpec & ' /c ' & 'wmic /node:' & @Computername &' product get name > %temp%\model.txt' ,"", @SW_HIDE) $file =(@TempDir & "/model.txt") $fileread = FileRead($file) GUICtrlCreateEdit($fileread, 5, 250, 395, 400) FileDelete(@TempDir & "/model.txt") EndFunc Surely a dumbass question but few hairs remains on my head
      Thanks