can´t find thread where i found this CODE

can´t find thread where i found this CODE

Postby Jimmy » Thu Sep 26, 2024 10:03 am

hi,
i have found this CODE, but don´t find the Thread again
Code: Select all  Expand view  RUN

********************************************************************************
FUNCTION FileDetails( cFilePath, cExeName )
********************************************************************************
   // Return 2d array with file details of cFilePath or empty array if failed.
   // If cFilePath is NIL tries to locate it in windows and program files folders
   // using FindPath( cExeName (if passed) )
   // cFilepath is the name of file with full path (e.g. 'C:\folder\xxx.exe')
   // Win only! since it uses "Shell.Application" service
   LOCAL aHeaders := { }
   LOCAL aValues := { }
   LOCAL aDetails := { }
   LOCAL oShell, oFolder, oItem, oInfo
   LOCAL i

   hb_Default( @cFilePath, "" )

   hb_Default( @cExeName, "" )

   // cExeName := SubStr( cFilePath, RAt( "\", cFilePath ) + 1 )
   cExeName := hb_FNameNameExt( cFilePath )

   IF Empty( cFilePath )
      RETURN { }
   ENDIF

   cFilePath := Left( cFilePath, RAt( "\", cFilePath ) - 1 )

   oShell  := win_oleCreateObject( "
Shell.Application" )

   oFolder := oShell:Namespace( cFilePath )

   // Store property names into aHeaders
   FOR i := 0 TO 288
      oInfo := oFolder:GetDetailsOf( oFolder:ITEMS, i )
      IF ! Empty( oInfo )
         AAdd( aHeaders, oInfo )
      ENDIF
   NEXT

   // get the file object
   oItem := oFolder:ParseName( cExeName )

   // MsgDebug( oItem, cExeName, cFilePath )

   // Store property values in aValues
   FOR i := 0 TO Len( aHeaders )
      oInfo := oFolder:GetDetailsOf( oItem, i )
      AAdd( aValues, oInfo )
   NEXT

   // Create aDetails 2-d array with property-value pairs
   FOR i := 1 TO Len( aValues )
      IF ! Empty( aValues[ i ] )
         AAdd( aDetails, { aHeaders[ i ], aValues[ i ] } )
      ENDIF
   NEXT

   RETURN aDetails

********************************************************************************
FUNCTION FileProperties( cFilePath, cExeName )
********************************************************************************
   // Return 2d array with file properties of cFilePath or empty array if failed.
   // If cFilePath is NIL tries to locate it in windows and program files folders
   // using FindPath( cExeName (if passed) )
   // cFilepath is the name of file with full path (e.g. 'C:\folder\xxx.exe')
   LOCAL oLocator, oCon, oFile, oItem, oSecurity
   LOCAL nPos, cAccess, nSize, cSize
   LOCAL hAccess := { 2032127     => "
Full Control"                   , ;
                      1179785     => "
Read"                           , ;
                      1180063     => "
Read, Write"                    , ;
                      1179817     => "
Read and Execute"               , ;
                      1245631     => "
Read and Execute, Modify, Write", ;
                      1180095     => "
Read and Execute, Write"        , ;
                      268435456   => "
Full Control (Sub Only)"        , ;
                      -1610612736 => "
Read and Execute Extended" }
   LOCAL aProperties := { }

   hb_Default( @cFilePath, "
" )
   hb_Default( @cExeName, "
" )

   IF Empty( cFilePath ) .OR. Left( cFilePath, 1 ) == "
<"
//      IF cExeName == 'System Idle Process' .OR. Empty( cFilePath := FindPath( cExeName ) )
      RETURN { }
//      ENDIF
   ENDIF

   oLocator := win_oleCreateObject( "
WbemScripting.SWbemLocator" )
   IF oLocator == NIL
      MsgStop(  "
Error: create WMI object. [" + win_oleErrorText() + "]" )
      RETURN { }
   ENDIF
   oCon  := oLocator:ConnectServer( "
.", "root\cimv2" )
   oSecurity := oCon:Security_
   oSecurity:ImpersonationLevel := 4

   cFilePath := StrTran( cFilePath, "
\", "\\" )

   oFile := oCon:ExecQuery( "
Select * from CIM_Datafile Where name = '" + cFilePath + "'" )


   FOR EACH oItem IN oFile

      IF HB_ISNIL( oItem )
         LOOP
      ENDIF

      IF ( ! HB_ISNIL( oItem:AccessMask ) ) .AND.  ( ( nPos := hb_HPos( hAccess, oItem:AccessMask ) ) > 0 )
         cAccess := hb_HValueAt( hAccess, nPos )
      ELSE
         cAccess := "
N/A"
      ENDIF
      nSize := Val( oItem:FileSize )

      IF .T.
         cSize := SHORTFILESIZE( nSize )
      ELSEIF nSize > 999999999
         cSize := Trans( nSize / 1024, "
@E 999,999,999" ) + " Kb"
      ELSE
         cSize := Trans( nSize, "
@E 999,999,999" ) + " bytes"
      ENDIF

      cSize += ( "
(" + LTrim(Trans( nSize, "@E 999,999,999,999" )) + " bytes)" )

      aProperties := { ;
                       { "
File name       : ", oItem:NAME }, ;
                       { "
Name            : ", oItem:FileName  } , ; //      { "8.3 file name   : ", oItem:EightDotThreeFileName } , ;
                       { "
Extension       : ", oItem:Extension } , ;
                       { "
File size       : ", AllTrim( cSize ) /*Trans( Val(oItem:FileSize)/1024, "@E 999,999,999" ) + " Kb"*/  }, ;
                       { "
Creation date   : ", WMI_DateTime2Str( oItem:CreationDate ) } , ;
                       { "
Last modified   : ", WMI_DateTime2Str( oItem:LastModified ) } , ;
                       { "
Last accessed   : ", WMI_DateTime2Str( oItem:LastAccessed ) } , ;
                       { "
File type       : ", oItem:FileType }, ;
                       { "
Archive         : ", Iif( oItem:Archive, "TRUE", "FALSE" ) }  , ;
                       { "
Compressed      : ", Iif( oItem:Compressed , "TRUE", "FALSE" ) } , ;
                       { "
Compres. method : ", oItem:CompressionMethod } , ;
                       { "
Readable        : ", Iif( oItem:Readable, "TRUE", "FALSE" ) } , ;
                       { "
Writeable       : ", Iif( oItem:Writeable, "TRUE", "FALSE" ) } , ;
                       { "
Encrypted       : ", Iif( oItem:Encrypted, "TRUE", "FALSE" ) } , ;
                       { "
Encrypt. method : ", oItem:EncryptionMethod } , ;
                       { "
Hidden          : ", Iif( oItem:Hidden, "TRUE", "FALSE" ) } , ;
                       { "
System          : ", Iif( oItem:System, "TRUE", "FALSE" ) } , ;
                       { "
Path            : ", oItem:Path } , ;
                       { "
File system name: ", oItem:FSName } , ;
                       { "
Access Rights   : ", cAccess } , ;
                       { "
Version         : ", oItem:Version } , ;
                       { "
Manufacturer    : ", oItem:Manufacturer } ;
                     }
      /*
      { "
Computer system name ", oItem:CSName } , ;
      { "
Drive ", oItem:Drive } , ;
      { "
File size " , Trans( Val(oItem:FileSize)/1024, "@E 999,999,999" ) + " Kb"  },;
      */

   NEXT

   RETURN aProperties

i have a Question about 2 missing Function
Turbo Incremental Link 6.97 Copyright (c) 1997-2022 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN_SHORTFILESIZE' referenced from C:\FWH\0\PROPERTY\FILEINFOFUNCS.OBJ
Error: Unresolved external '_HB_FUN_WMI_DATETIME2STR' referenced from C:\FWH\0\PROPERTY\FILEINFOFUNCS.OBJ
Error: Unable to perform link
* Linking errors *

Who know this Thread or those missing Functions :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: can´t find thread where i found this CODE

Postby Antonio Linares » Thu Sep 26, 2024 10:43 am

You may try with these ones:

Code: Select all  Expand view  RUN
FUNCTION SHORTFILESIZE( nSize )
   LOCAL cSize

   IF nSize >= 1024 * 1024
      cSize := LTrim( Str( nSize / ( 1024 * 1024 ), 10, 2 ) ) + " Mb"
   ELSEIF nSize >= 1024
      cSize := LTrim( Str( nSize / 1024, 10, 2 ) ) + " Kb"
   ELSE
      cSize := LTrim( Str( nSize, 10 ) ) + " bytes"
   ENDIF

   RETURN cSize
 

Code: Select all  Expand view  RUN
FUNCTION WMI_DateTime2Str( cWMIDate )
   LOCAL cYear, cMonth, cDay, cHour, cMinute, cSecond, cFormattedDate

   IF Len( cWMIDate ) < 14
      RETURN ""
   ENDIF

   // Extraer partes de la fecha
   cYear   := SubStr( cWMIDate, 1, 4 )
   cMonth  := SubStr( cWMIDate, 5, 2 )
   cDay    := SubStr( cWMIDate, 7, 2 )
   cHour   := SubStr( cWMIDate, 9, 2 )
   cMinute := SubStr( cWMIDate, 11, 2 )
   cSecond := SubStr( cWMIDate, 13, 2 )

   // Formato legible
   cFormattedDate := cDay + "/" + cMonth + "/" + cYear + " " + cHour + ":" + cMinute + ":" + cSecond

   RETURN cFormattedDate
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests