Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 6 Monaten, 3 Wochen
Letzter Beitrag:
vor 6 Monaten, 3 Wochen
Beteiligte Autoren:
Ola, Fabrice Harari

[WD21] How to check/run stupid exefilenames?

Startbeitrag von Ola am 24.01.2017 23:40

Hi all

Can somebody please teach me how to check for existence and run stupid, long filenames with spaces in their path, like

//The filename is saved in a file like this:
XPARAM.Filename = "C:\StupidProgram Files (x86)\Stupid Subdirectory\Stupid.exe"
//That is, it is in the item without the "inch marks"

sStupidFileName is string = XPARAM.Filename

IF NOT fFileExist(sStupidFileName) THEN
//The stupid file is never found because it has spaces in the path!
Warning("The stupid file is not found:" + sStupidFileName)
ReturnToCapture()
END

ExeRun(sStupidFileName)

The help for Exerun tells to use [] or three """inch marks""", but how do I do that for a file item/Variable? The help for fFileExist does not seem to recognize this problem at all.

Best regards
Ola

Antworten:

Hi Ola,

replace is your friend:

MyString is string=charact(34)+"%1"+charact(34)
MyString=REplace(MyString,"%1",sStupidFileName)
exerun(MyString)

Very simple...

Best regards

von Fabrice Harari - am 25.01.2017 01:31
Hi Fabrice,

Yes, elementary, actually:-), Thank you!

It turned out that this was caused not only by the "space in the path" problem,
but also the "requires elevation (740)" problem (which can be solved
-- at least in this case -- by using ShellExecute instead of ExeRun, see:
http://27130.foren.mysnip.de/read.php?27131,490533,490877#msg-490877 )
and the fact that fFileExist and ExeRun and ShellExecute handle the spaces
differently.

I made a function of it like this:


//Preparations in the calling code:
//Extract the program name from the button's name:
//sProgramName is string = ExtractString(Myself..Name,2,"_") //Eg. BTN_Stupid
//sExeFileName is string = "C:\Program Files (x86)\Stupid Subdir\Stupid.exe"

FUNCTION ExecuteExe(sProgramName,sExeFileName)

sExeFileName = NoSpace(sExeFileName) //Cut leading and trailing spaces away

MyString is string = ""
ExistRes is boolean = False
IF Position(sExeFileName," ") THEN //If there are spaces...
MyString = Charact(34)+"%1"+Charact(34) //Add the inch marks
MyString = Replace(MyString,"%1",sExeFileName)
MyString = Replace(MyString,"""","") //Cut off the inch marks!!!!!!
IF OnTestMode THEN Info("Test (w/spaces): MyString = " + MyString)
ExistRes = fFileExist(MyString)
IF ExistRes = False THEN
Warning(XMsg("ProgramNotFound:"),sProgramName,sExeFileName)
RESULT False
END
ELSE
MyString = sExeFileName
IF OnTestMode THEN Info("Test (no spaces): MyString = " + MyString)
ExistRes = fFileExist(MyString)
IF ExistRes = False THEN
Warning(XMsg("ProgramNotFound:"),sProgramName,sExeFileName)
RESULT False
END
END

//ExeRes is boolean = ExeRun(MyString) //Causes "Needs elevation" (740) error!
RunRes is boolean = ShellExecute(MyString) //This works!
IF RunRes = False THEN
Error(XMsg("NotExecuted:",sProgramName,MyString) +CR+ ErrorInfo())
RESULT False
END

RESULT True

Best regards
Ola

von Ola - am 25.01.2017 13:31
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.