Sign in to follow this  
Followers 0
Guest Guest_oYx

"Run" broken by brackets in filename

7 posts in this topic

here is a simplified example of how it doesn't run:

Run (@ComSpec & " /c C:\(test).txt")

here is the actual line from my script, which allows me to run any file that windows recognises:

Run (@ComSpec & " /c " & """" & $targetpath & $file & """", "", @SW_HIDE)

any idea how to resolve that? :D

Share this post


Link to post
Share on other sites



i realised brackets are not the only problem. the ampersand (&) in filenames affects the script too.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

here is the actual line from my script, which allows me to run any file that windows recognises

Not quite. You can't run anything except Exe and Com files without using the application required to run them. For example, if you had the full path of a text file in $file, you could open them with notepad by using:

Run(@ComSpec & " /c notepad.exe " & '"' & $file & '"', "", @SW_HIDE)

If your filename contains the "&" character, it shouldn't matter.

Typo corrected

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

This seems to work:

Run(@ComSpec & ' /k ""C:\(test).txt""')

as does this (odd looking) bit:

Run(@ComSpec & ' /k C:\"(test).txt"')

Perhaps double quotes will also fix the ampersand issue, too.

The last paragraph of a cmd /? says this:

The special characters that require quotes are:

  <space>

  &()[]{}^=;!'+,`~

Possible reason this occurs: The double quotes are necessary because of the way the command line works. Let's break down what each program is getting:

Using this string:

@ComSpec & ' /k "C:\(test).txt"'

Console (@ComSpec) gets this string passed to it:

/k C:\(test).txt

Notice the lack of quotes around the file name. That's because they were stripped when passed. Now, when the command interpreter tries to run it, it errors because file names with () need to be in quotes.

Now take the string:

@ComSpec & ' /k ""C:\(test).txt""'

The command interpreter gets:

/k "C:\(test).txt"

So now when it tries to run the file name to open it, it has a properly quoted file name to use.

This may seem very confusing, but it is normal. I can reproduce all the success and failure cases with or without AutoIt.

Share this post


Link to post
Share on other sites

Not quite.  You can't run anything except Exe and Com files without using the application required to run them.

not true. :D

i have used it to run any file that i can run by double-clicking on in windows explorer. for example: mp3, avi, mid, jpg, wav, etc.

as long as it's already associated with the program that runs the file in windows, that line will run them.

Share this post


Link to post
Share on other sites

Valik,

i'm going to accuse you of being nice now. :D

thanks for your time in replying. i'll try your method out now.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Run (@ComSpec & " /c " & '""' & $file & '""', "", @SW_HIDE)

that runs every file now - even with special characters in the filename.

thanks for the push in the right direction! :D

Edited by oYx

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
Sign in to follow this  
Followers 0