Author Topic: FUNCTION FOR OPEN or SELECT A FILE (Windows)  (Read 3248 times)

0 Members and 1 Guest are viewing this topic.

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
FUNCTION FOR OPEN or SELECT A FILE (Windows)
« on: May 05, 2021, 08:04:27 am »
Here a little function for select or open a file...

FIRST USE: select one file (getting his name and directory)

myfile$ = FILESELECTOR$("")
IF myfile$ = "" THEN PRINT "No file choosen" ELSE PRINT "Your choice is" + CHR$(13) + myfile$
SLEEP
END


SECOND USE
select a file and open it !
myfile$ = FILESELECTOR$("OPEN")
The file you select will be opened with the current windows application :
'XLS file--> Excel, DOC--> Word, PDF-->Acrobat JPG-->Picture program... aso

Hope usefull...



Code: QB64: [Select]
  1. FUNCTION FILESELECTOR$ (FS$) '  FS$ = "" select 1 file // FS$ ="OPEN"--> open the file with it's current windows application
  2.     _CLIPBOARD$ = "": FS2$ = CHR$(13) + CHR$(10): FS3$ = "echo": IF UCASE$(FS$) = "OPEN" THEN FS3$ = ""
  3.     FS1$ = "Set wShell = CreateObject(²WScript.Shell²)" + FS2$
  4.     FS1$ = FS1$ + "Set oExec = wShell.Exec(²mshta.exe ²²about:<input type=file "
  5.     FS1$ = FS1$ + "id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')."
  6.     FS1$ = FS1$ + "GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>²²²)" + FS2$
  7.     FS1$ = FS1$ + "sFileSelected = oExec.StdOut.ReadLine" + FS2$
  8.     FS1$ = FS1$ + "Set WshShell = WScript.CreateObject(²WScript.Shell²)" + FS2$
  9.     FS1$ = FS1$ + "WshShell.Run ²cmd.exe /c " + FS3$ + " ² & sFileSelected & ² | clip², 0, TRUE" + CHR$(13)
  10.     FS1$ = FS1$ + "set Wshell=nothing" + FS2$ + "set WshShell=nothing" + FS2$:
  11.     FS4: J = INSTR(FS1$, "²"): IF J > 0 THEN MID$(FS1$, J, 1) = CHR$(34): GOTO FS4
  12.     ficvbs$ = _CWD$ + "TEMP_FS.vbs": CanalLibre% = FREEFILE: OPEN ficvbs$ FOR OUTPUT AS CanalLibre%
  13.     PRINT #1, FS1$: CLOSE CanalLibre%: _DELAY 0.1: SHELL _HIDE "cscript  //NoLogo " + ficvbs$: _DELAY .5: KILL ficvbs$
  14.     IF INSTR(_CLIPBOARD$, " ECHO ") > 0 THEN _CLIPBOARD$ = ""
  15.     FILESELECTOR$ = _CLIPBOARD$
  16.  
  17.  
Why not yes ?

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: FUNCTION FOR OPEN or SELECT A FILE (Windows)
« Reply #1 on: May 08, 2021, 02:06:29 pm »
Thaks! It's very useful