Folder Selection

66 views
Skip to first unread message

Antonio Cardinaux

unread,
Oct 16, 2025, 11:48:39 AM (15 hours ago) Oct 16
to Harbour Users
I have 4 files, 2 with DBF extensions and 2 with CDX extensions, in the Windows temporary folder.

hb_GetEnv("temp")

I want to move these files to a folder of the user's choice. What command in Harbor allows me to select that folder?

Antonio

matt johnson

unread,
Oct 16, 2025, 1:14:57 PM (14 hours ago) Oct 16
to harbou...@googlegroups.com
Set default to "C:\folder"
--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/9f3b63f1-272c-46a2-a052-df03917a82bbn%40googlegroups.com.

Antonio Cardinaux

unread,
Oct 16, 2025, 1:20:30 PM (14 hours ago) Oct 16
to Harbour Users
The user chooses the folder. In graphical mode, they would use:

GetFolder()

But in pure Harbour, what do I use?

cod...@outlook.com

unread,
Oct 16, 2025, 2:12:46 PM (13 hours ago) Oct 16
to Harbour Users

Hi Antonio.

If you need to do it in non-gui (text mode) Harbour program, as I know there is no Harbour command to select folder. There is no command which will prepare list of all folders on some drive (C: or D: or ...) and give it to user to select desired one.

You must use DIRECTORY() function, see link https://harbour.github.io/doc/clc53.html#directory .

Question is what folders (and subfolders) user can see and select. If users can see  folders and its subfolders, you must write some recursive function with  DIRECTORY() function to get list of all folders and put them in some array. Then use that array of directories and  make some browse function with which user will select desired folder. In browse function you can use Harbour ACHOICE() function or TBROWSE object.

I used DIRECTORY() only to list and select files from predefined folder, not to select folders.

You can ask ChatGPT how to get list of folders and how to browse array and will get usefull starting point.

Regards,

Simo.

Daniele Campagna

unread,
Oct 16, 2025, 6:24:20 PM (8 hours ago) Oct 16
to harbou...@googlegroups.com

A C function:

#pragma BEGINDUMP

#include "hbapi.h"
#include <windows.h>
#include "hbapiitm.h"
#include <shlobj.h>
#include "hbvm.h"
#include "hbstack.h"

//SYNTAX: SHBrowseForFolder([<hWnd>],[<cTitle>],<nFlags>,[<nFolderType>])
HB_FUNC( SHBROWSEFORFOLDER )
{
   HWND hwnd = ISNIL   (1)  ? GetActiveWindow() : (HWND) hb_parnl(1);
   BROWSEINFO BrowseInfo;
   char *lpBuffer = (char*) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation(hwnd, ISNIL(4) ? CSIDL_DRIVES : hb_parni(4), &pidlBrowse) ;
   BrowseInfo.hwndOwner = hwnd;
   BrowseInfo.pidlRoot = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle = ISNIL (2) ?  "Select a Folder" : hb_parcx(2);
   BrowseInfo.ulFlags = hb_parni(3);
   BrowseInfo.lpfn = NULL;
   BrowseInfo.lParam = 1;
   BrowseInfo.iImage = 0;
   pidlBrowse = SHBrowseForFolder(&BrowseInfo);

   if ( pidlBrowse )
   {
     SHGetPathFromIDList(pidlBrowse,lpBuffer);
     hb_retc( lpBuffer );
   }
   else
   {
     hb_retc( "" );
   }

   hb_xfree( lpBuffer);
}
#pragma ENDDUMP

Use:

    cNewdir=shbrowseforfolder(,"Choose directory")

HTH

Dan

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

marcos...@gmail.com

unread,
Oct 16, 2025, 10:05:16 PM (5 hours ago) Oct 16
to Harbour Users
Code correction in C, the function is HB_ISNIL()

#pragma BEGINDUMP

#include "hbapi.h"
#include <windows.h>
#include "hbapiitm.h"
#include <shlobj.h>
#include "hbvm.h"
#include "hbstack.h"

//SYNTAX: SHBrowseForFolder([<hWnd>],[<cTitle>],<nFlags>,[<nFolderType>])
HB_FUNC( SHBROWSEFORFOLDER )
{
   HWND hwnd = HB_ISNIL(1)  ? GetActiveWindow() : (HWND) hb_parnl(1);

   BROWSEINFO BrowseInfo;
   char *lpBuffer = (char*) hb_xgrab( MAX_PATH + 1 );
   LPITEMIDLIST pidlBrowse;

   SHGetSpecialFolderLocation(hwnd, HB_ISNIL(4) ? CSIDL_DRIVES : hb_parni(4), &pidlBrowse) ;

   BrowseInfo.hwndOwner = hwnd;
   BrowseInfo.pidlRoot = pidlBrowse;
   BrowseInfo.pszDisplayName = lpBuffer;
   BrowseInfo.lpszTitle = HB_ISNIL(2) ?  "Select a Folder" : hb_parcx(2);

   BrowseInfo.ulFlags = hb_parni(3);
   BrowseInfo.lpfn = NULL;
   BrowseInfo.lParam = 1;
   BrowseInfo.iImage = 0;
   pidlBrowse = SHBrowseForFolder(&BrowseInfo);

   if ( pidlBrowse )
   {
     SHGetPathFromIDList(pidlBrowse,lpBuffer);
     hb_retc( lpBuffer );
   }
   else
   {
     hb_retc( "" );
   }

   hb_xfree( lpBuffer);
}
#pragma ENDDUMP


PROCEDURE main()

    cNewdir := shbrowseforfolder(,"Choose directory")

    ? cNewdir

    WAIT

RETURN

----
hb_IsNIL(xExp) ➜ lResult
determines if <xExp> evaluates to NIL (valtype "U").
Reply all
Reply to author
Forward
0 new messages