Sign in to follow this  
Followers 0
Mr.Furious

White space in filename

16 posts in this topic

Is there a way to get this code to still work if the filename has a space in it?

$search = FileFindFirstFile("*.imc")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files matched *.imc")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop

    $attrib = FileGetAttrib($file)
    
  ; Skip directories    
    If StringInStr($attrib, "D") Then ContinueLoop  

    RunWait ("ShelExec "& $file)

WEnd

; Close the search handle
FileClose($search)

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

great that works, so getting a little more serious what is the conversion for this?

RunWait ($CmdLine[1] & " " & $CmdLine[2] & $file)

Format: $CmdLine[1] $CmdLine[2] $file

"ShelExec" "my folder\" "my file.jpg"

Edited by Mr.Furious

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

RunWait ($CmdLine[1] & " " & $CmdLine[2] & " '" & $file & "'")

<{POST_SNAPBACK}>

Doesn't work as expected opens the folder instead of the file.

My brain doesn't seem to be focusing correctly. I can't seem to understand the concept.

Edited by Mr.Furious

Share this post


Link to post
Share on other sites

THIS WORKS:

RunWait ('ShelExec.exe "' & $CmdLine[2] & $file & '"')

but I still need to get the initial variable for the external program to work in there.

Funny how everything loved life until a folder or file had a space in it.

Share this post


Link to post
Share on other sites

It's beacuse of the way DOS commands (and Windows internally) handles file paths. If there are spaces in the path, the cmd path has to be enclosed in quotes. Thats in additon to any quotes needed by the script command. You can also use the short version of the path where quotes aren't needed:

"C:\Program Files" becomes C:\PROGRA~1

"C:\Programming codes\My scripts" becomes C:\PROGRA~2\MYSCRI~1


AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

Thanks for the tips, I think you misuderstood, I am trying to get this to work:

RunWait ('$CmdLine[1] "' & $CmdLine[2] & $file & '"')

The variables would = for example "ShelExec.exe" "my folder\" "my file.jpg"

arggghh I think white spaces will be chasing me in my dreams tonight.

RunWait ('ShelExec.exe "' & $CmdLine[2] & $file & '" ' & $cmd)

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I don't have ShelEec.exe but i got this to work:

$cmd1 = "notepad.exe"

$cmd2 = "C:\Program Files\"

$cmd3 = "test 1.txt"

RunWait ($cmd1 & " " & $cmd2 & $cmd3)

Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Your right using notepad the problem goes away.

However if I can just get ShelExec.exe into a varialbe without screwing up the part of the line that works it will work.

RunWait ('ShelExec.exe "' & $CmdLine[2] & $file & '"')

Edited by Mr.Furious

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Edit:

$cmd1 = "shelexec.exe"

$cmd2 = "C:\Program Files\"

$cmd3 = "test 1.txt"

RunWait ($cmd1 & ' "' & $cmd2 & $cmd3 & '"')

Edited by steveR

AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Did that work for you?

OPPS forgot to compile before testing!!

Thanks a bunch

Edited by Mr.Furious

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

It seems to be working fine just needed that one damn apostrophe' in the right spot! eeeeek

Sorry thought the script was gonna complicate things.

Format OpenAll.exe "program.exe" "myfiles\" "*.jpg"

Here is the script:

$search = FileFindFirstFile($CmdLine[2] & $CmdLine[3])  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files matched " & $CmdLine[3] & " in the " & $CmdLine[2] & " folder.")

    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop

    $attrib = FileGetAttrib($file)
    
  ; Skip directories    
    If StringInStr($attrib, "D") Then ContinueLoop    
        
    RunWait ($CmdLine[1] & ' "' & $CmdLine[2] & $file & '"')
    
WEnd

; Close the search handle
FileClose($search)

yes, it works for me.

I caught your script before it left, but i dont know how to implement it. take some more work

<{POST_SNAPBACK}>

Edited by Mr.Furious

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