Newsgroup: it.comp.programmare.win32
Titolo: direcotry - come vedo i contenuti?

quali API devo usare per aprire una cartella e vedere tutti i files
contenuti in essa, o magari solo i files con una certa estensione?
ciao
AL3



Esempio (da MSDN):
------------------
#include "windows.h"
int
main(int argc, char *argv[])
{
  WIN32_FIND_DATA FindFileData;
  HANDLE hFind;
  printf ("Target file is %s.\n", argv[1]);
  hFind = FindFirstFile(argv[1], &FindFileData);
  if (hFind == INVALID_HANDLE_VALUE) {
    printf ("Invalid File Handle. Get Last Error reports %d\n",
GetLastError ());
  } else {
    printf ("The first file found is %s\n", FindFileData.cFileName);
    FindClose(hFind);
  }
  return (0);
}
Per leggere tutti i file:
-------------------------
FindNextFile
The FindNextFile function continues a file search from a previous call
to the FindFirstFile function. 
BOOL FindNextFile(
  HANDLE hFindFile,                // search handle 
  LPWIN32_FIND_DATA lpFindFileData // data buffer
);
Parameters
hFindFile 
[in] Search handle returned by a previous call to the FindFirstFile
function. 
lpFindFileData 
[out] Pointer to the WIN32_FIND_DATA structure that receives
information about the found file or subdirectory. The structure can be
used in subsequent calls to FindNextFile to refer to the found file or
directory.
Dati dei vari file:
-------------------
typedef struct _WIN32_FIND_DATA {
  DWORD    dwFileAttributes; 
  FILETIME ftCreationTime; 
  FILETIME ftLastAccessTime; 
  FILETIME ftLastWriteTime; 
  DWORD    nFileSizeHigh; 
  DWORD    nFileSizeLow; 
  DWORD    dwReserved0; 
  DWORD    dwReserved1; 
  TCHAR    cFileName[ MAX_PATH ]; 
  TCHAR    cAlternateFileName[ 14 ]; 
} WIN32_FIND_DATA, *PWIN32_FIND_DATA; 
Luc.

 wrote:

Questa va benissimo e fa tutto lei :
The GetOpenFileName function creates an Open common dialog box that
lets the user specify the drive, directory, and the name of a file or
set of files to open. 
BOOL GetOpenFileName(
    LPOPENFILENAME lpofn 	// address of structure with
initialization data
   );	
 
Parameters
lpofn
Pointer to an OPENFILENAME structure that contains information used to
initialize the dialog box. When GetOpenFileName returns, this
structure contains information about the user's file selection. 
 
Return Values
If the user specifies a filename and clicks the OK button, the return
value is nonzero. The buffer pointed to by the lpstrFile member of the
OPENFILENAME structure contains the full path and filename specified
by the user.
If the user cancels or closes the Open dialog box or an error occurs,
the return value is zero. To get extended error information, call the
CommDlgExtendedError function, which can return one of the following
values: 
CDERR_FINDRESFAILURE	CDERR_NOHINSTANCE
CDERR_INITIALIZATION	CDERR_NOHOOK
CDERR_LOCKRESFAILURE	CDERR_NOTEMPLATE
CDERR_LOADRESFAILURE	CDERR_STRUCTSIZE
CDERR_LOADSTRFAILURE	FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAILURE	FNERR_INVALIDFILENAME
CDERR_MEMLOCKFAILURE	FNERR_SUBCLASSFAILURE
 
Remarks
By default, Windows 95 and Windows NT version 4.0 display a new
version of the Open dialog box that provides user-interface features
that are similar to the Windows Explorer. You can provide an
OFNHookProc hook procedure for an Explorer-style Open dialog box. To
enable the hook procedure, set the OFN_EXPLORER and OFN_ENABLEHOOK
flags in the Flags member of the OPENFILENAME structure and specify
the address of the hook procedure in the lpfnHook member. 
Windows 95 and Windows NT 4.0 continue to support the old-style Open
dialog box for applications that want to maintain a user-interface
consistent with the Windows 3.1 or Windows NT 3.51 user-interface. To
display the old-style Open dialog box, enable an OFNHookProcOldStyle
hook procedure and ensure that the OFN_EXPLORER flag is not set.
See Also
CommDlgExtendedError, GetSaveFileName, OFNHookProc ,
OFNHookProcOldStyle, OPENFILENAME 

Prima di tutto, devi aprire proprio la directory in explorer? Se ad
esempio tu vuoi aprire la directory C: puoi usare:
ShellExecute(HWND hwnd, LPCTSTR lpVerb, LPCTSTR lpFile, LPCTSTR
lpParameters, LPCTSTR lpDirectory);
in questo modo:
ShellExecute(NULL, "open", "C:\\", NULL, NULL);
oppure per visualizzare solo i file exe:
ShellExecute(NULL, "open", "C:\\", "*.exe", NULL);
Spero di averti dato una mano.