Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Win32api::File and Directories

by BrowserUk (Patriarch)
on Jun 15, 2005 at 21:19 UTC ( [id://467062]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Win32api::File and Directories
in thread Win32api::File and Directories

Maybe this will help

#! perl -slw use strict; use Win32::API::Prototype; ApiLink( 'Kernel32', q[ HANDLE FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpF +FData )] ) or die $^E; ApiLink( 'Kernel32', q[ BOOL FindNextFile( HANDLE hFindFile, LPWIN32_FIND_DATA lpFFData + ) )] ) or die $^E; ApiLink( 'Kernel32', q[ HANDLE FindClose( HANDLE hFindDile )] ) or die $^E; =pod typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; # 4 FILETIME ftCreationTime; # 8 FILETIME ftLastAccessTime; # 8 FILETIME ftLastWriteTime; # 8 DWORD nFileSizeHigh; # 4 DWORD nFileSizeLow; # 4 DWORD dwReserved0; # 4 DWORD dwReserved1; # 4 TCHAR cFileName[MAX_PATH]; # 260 TCHAR cAlternateFileName[14]; # 14 } WIN32_FIND_DATA, # 328 *PWIN32_FIND_DATA; =cut my $FFData = chr(0) x 328; my $hFF = FindFirstFile( '.\*', $FFData ) or die $^E; do { print unpack 'x44Z260', $FFData; } while FindNextFile( $hFF, $FFData ); FindClose( $hFF );

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^4: Win32api::File and Directories
by Droid41 (Initiate) on Jun 15, 2005 at 22:00 UTC
    That looks quite promising, thanks! I'll play around with that.

      Here's a version that attempts to use the W(ide) unicode api's, but I cannot work out the right syntax for passing the filespec to search for?

      #! perl -slw use strict; use Win32::API::Prototype; ApiLink( 'Kernel32', q[ HANDLE FindFirstFileW( LPCTSTR lpFileName, LPW +IN32_FIND_DATA lpFindFileData )] ) or die $^E; ApiLink( 'Kernel32', q[ BOOL FindNextFileW( HANDLE hFindFile, LPWIN32_ +FIND_DATA lpFindFileData ) )] ) or die $^E; ApiLink( 'Kernel32', q[ HANDLE FindClose( HANDLE hFindDile )] ) or die + $^E; =pod typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; # 4 FILETIME ftCreationTime; # 8 FILETIME ftLastAccessTime; # 8 FILETIME ftLastWriteTime; # 8 DWORD nFileSizeHigh; # 4 DWORD nFileSizeLow; # 4 DWORD dwReserved0; # 4 DWORD dwReserved1; # 4 TCHAR cFileName[MAX_PATH]; # 260 TCHAR cAlternateFileName[14]; # 14 } WIN32_FIND_DATA, # 328 *PWIN32_FIND_DATA; =cut my $FFData = chr(0) x 1024; ## Allow some extra room for long unicode +paths? ## See the MSDN docs for where the \\?\... syntax comes from ## It is recognising this syntax as without it I get ## The filename, directory name, or volume label syntax is incorrect ## And with it I get ## The system cannot find the file specified ## Which suggests that it can't file any file in the path I'm specifyi +ng ## but there are files there to be found. my $hFF = FindFirstFileW( '\\?\p:\test\*', $FFData ) > 0 or die $^E; ## Note: the > 0 test above Failure results in a -1 returncode. print $hFF; do { print unpack 'x44U*', $FFData; } while FindNextFileW( $hFF, $FFData ); __END__ P:\test>ffw The system cannot find the file specified at P:\test\FFW.pl line 27.

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467062]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-16 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found