Author Topic: Selecting a folder (a little vbs function)  (Read 1385 times)

0 Members and 1 Guest are viewing this topic.

Offline euklides

  • Forum Regular
  • Posts: 128
Selecting a folder (a little vbs function)
« on: April 10, 2022, 10:54:15 am »
Little function to select a folder with VBS
(win systems)
Code: QB64: [Select]
  1. MYREP$ = REPSELECTOR$("D:"): Print MYREP$
  2. MYREP$ = REPSELECTOR$(""): Print MYREP$: Sleep
  3.  
  4. Function REPSELECTOR$ (repertoiredemarrage$)
  5.     Repz$ = repertoiredemarrage$:  FS2$ = Chr$(13) + Chr$(10)
  6.     fs1$ = "Dim objFolder, objItem, objShell" + FS2$
  7.     fs1$ = fs1$ + "On Error Resume Next" + FS2$
  8.     fs1$ = fs1$ + "SelectFolder = vbNull" + FS2$
  9.     fs1$ = fs1$ + "myStartFolder = " + "²" + Repz$ + "²" + FS2$
  10.     fs1$ = fs1$ + "Set objShell  = CreateObject( ²Shell.Application² )" + FS2$
  11.     fs1$ = fs1$ + "Set objFolder = objShell.BrowseForFolder( 0, ²Select Folder², 0, myStartFolder )" + FS2$
  12.     fs1$ = fs1$ + "If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path" + FS2$
  13.     fs1$ = fs1$ + "Set WshShell = WScript.CreateObject(²WScript.Shell²)" + FS2$
  14.     fs1$ = fs1$ + "WshShell.Run ²cmd.exe /c echo ² & SelectFolder & ² | clip², 0, TRUE   " + FS2$
  15.     FS5: J = InStr(fs1$, "²"): If J > 0 Then Mid$(fs1$, J, 1) = Chr$(34): GoTo FS5
  16.     ficvbs$ = _CWD$ + "\TEMP_FS.vbs": CanalLibre% = FreeFile: Open ficvbs$ For Output As CanalLibre%
  17.     Print #1, fs1$: Close CanalLibre%: _Delay 0.1:
  18.     Shell ficvbs$: Kill ficvbs$
  19.     REPSELECTOR$ = _Clipboard$
  20.  
Why not yes ?