none
The system cannot find the file specified RRS feed

  • Question

  • I've played around with VBA in access for a few years now, so a team approached me to work on some HTA files with VBscript in them. All seemed good, my testing was working until all of a sudden I got the error:

    The system cannot find the file specified

    It points to a line that was working fine before where I call shell.run fileSpec

    where shell is a WScript.Shell object, and fileSpec is a file path. This was all working before.  I have an If statement checking the file path before use:

    	If (fso.FileExists(fileSpec)) Then
    		aMsg = fileSpec & " exists."
    		shell.run fileSpec
    	Else
    		aMsg = "--==FILE NOT FOUND==--"
        End If
    	MsgBox aMsg
    So the file path exists or the shell.run would be skipped.  If I comment out the shell.run line, I get the message that the file and path exist.  Why am I all of a sudden getting this error?

    Thursday, December 8, 2016 1:43 PM

Answers

  • spaces -

    filespec = """C:\program files\Internet Explorer\iexplore.exe"""
    shell.run fileSpec


    \_(ツ)_/

    • Marked as answer by InLaNoche Thursday, December 8, 2016 2:57 PM
    Thursday, December 8, 2016 2:02 PM
  • I had tried that and had other issues, but this was the root of the issue.  There were a few things that lead up to this, which I just discovered that made the issue so 'wack'.  First off, my initial test was with this path:

    D:\users\myaccount\OneDrive - Corp\GDM work\WelcometoOneDrive\temp.bat

    This kind of worked as it opened up a folder.  This was because I also had a regular onedrive folder:

    D:\users\myaccount\OneDrive

    So this folder opened up (as the path ended at the first space).  This is what screwed me up.

    Also, to add to this, shell.run requires quotes around the path with spaces, fso.FileExists() cannot use quotes.  So with the quotes (as you showed above) the If statement would fail...

    So what I need to do is to add the quotes after the file is found, and I have found some other posts dealing with parms for EXEs with the shell.run, which I will be implementing.

    Thanks for the reply!

    • Marked as answer by InLaNoche Thursday, December 8, 2016 2:57 PM
    Thursday, December 8, 2016 2:56 PM

All replies

  • spaces -

    filespec = """C:\program files\Internet Explorer\iexplore.exe"""
    shell.run fileSpec


    \_(ツ)_/

    • Marked as answer by InLaNoche Thursday, December 8, 2016 2:57 PM
    Thursday, December 8, 2016 2:02 PM
  • I had tried that and had other issues, but this was the root of the issue.  There were a few things that lead up to this, which I just discovered that made the issue so 'wack'.  First off, my initial test was with this path:

    D:\users\myaccount\OneDrive - Corp\GDM work\WelcometoOneDrive\temp.bat

    This kind of worked as it opened up a folder.  This was because I also had a regular onedrive folder:

    D:\users\myaccount\OneDrive

    So this folder opened up (as the path ended at the first space).  This is what screwed me up.

    Also, to add to this, shell.run requires quotes around the path with spaces, fso.FileExists() cannot use quotes.  So with the quotes (as you showed above) the If statement would fail...

    So what I need to do is to add the quotes after the file is found, and I have found some other posts dealing with parms for EXEs with the shell.run, which I will be implementing.

    Thanks for the reply!

    • Marked as answer by InLaNoche Thursday, December 8, 2016 2:57 PM
    Thursday, December 8, 2016 2:56 PM
  • The rule is actually pretty simple. Filenames cannot contain quotes. Period/full stop.

    Quotes are used to encapsulate a file or path name for a command line parser: For example, a command line with cmd.exe or PowerShell (or, in this case, the WshShell object's Run method).

    This article explains in more detail:

    Command lines need to be quoted; paths don't

    Once you understand this, things get a lot clearer and easier.


    -- Bill Stewart [Bill_Stewart]



    Thursday, December 8, 2016 3:22 PM
    Moderator