ShellExecuteW() (does a folder exist?)

New to FreeBASIC? Post your questions here.
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

ShellExecuteW() (does a folder exist?)

Postby newbieforever » Jan 25, 2019 11:40

Hi!

I am unable to find out whether ShellExecuteW() returns a usable value.
I would be interested to get the echo of a DOS command, but this probably will be impossible...

So long!

Code: Select all

ShellExecuteW(0, "open", "cmd.exe", "if exist aSubFolder echo yes", 0, SW_HIDE)
Last edited by newbieforever on Jan 25, 2019 13:06, edited 1 time in total.
jj2007
Posts: 1523
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: ShellExecuteW()

Postby jj2007 » Jan 25, 2019 12:49

Try your luck with

Code: Select all

#include once "Windows.bi"
#include once "win/shellapi.bi" 

  Dim as integer RetVal=ShellExecuteW(0, 0, "cmd.exe", "/c if not exist aSubFolder echo NO >1.txt", 0, SW_SHOW)
  print "ShellExecuteW returned";RetVal
  sleep

For RetVal<=32 check GetLastError. Ignore the silly warning. Of course, you must retrieve the 1.txt with a FileRead$("1.txt") of some sort. Roll your own.
newbieforever
Posts: 117
Joined: Jun 21, 2018 11:14

Re: ShellExecuteW() (does a folder exist?)

Postby newbieforever » Jan 25, 2019 13:05

OK, I understand, thank you verry much, jj2007.

Btw: windows.bi includes the function GetFileAttributes(), which returns 16 for an existing folder. And (what a surprise!) this function seems to support Unicode!!!

This seems to be the simpliest way...

So long!

Code: Select all

#Define Unicode
#Include once "windows.bi"

Print GetFileAttributes("Čoć")       ' If the subfolder "Čoć" exists, the returned value is 16.
Last edited by newbieforever on Jan 25, 2019 13:32, edited 1 time in total.
jj2007
Posts: 1523
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: ShellExecuteW() (does a folder exist?)

Postby jj2007 » Jan 25, 2019 13:29

newbieforever wrote:This seems to be the simpliest way...
Sometimes I wonder why a BASIC dialect doesn't have BASIC functions like FileRead$() or IsFolder() ;-)

Code: Select all

  .if IsFolder("временная папка")
       Inkey "temp folder exists"
  .else
       Inkey "no temp folder"
  .endif
grindstone
Posts: 726
Joined: May 05, 2015 5:35
Location: Germany

Re: ShellExecuteW() (does a folder exist?)

Postby grindstone » Jan 26, 2019 14:18

jj2007 wrote:Sometimes I wonder why a BASIC dialect doesn't have BASIC functions like FileRead$() or IsFolder() ;-)

Something like this?

Code: Select all

#Include "dir.bi"

If Len(Dir("временная папка", fbDirectory)) Then
   Print "temp folder exists"
Else
   Print "no temp folder"
EndIf

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 4 guests