FOR/NEXT into FOR EACH

FOR/NEXT into FOR EACH

Postby Jimmy » Mon Jan 02, 2023 2:48 pm

hi,

i like to change FOR / NEXT into FOR EACH

Code: Select all  Expand view
FUNCTION GetMetaData( cPath, cFilename )
LOCAL nItem, iMax := 333
LOCAL objShell := CreateObject( "Shell.Application" )

   objFolder := objShell:Namespace( cPath )
   objFolderItem := objFolder:ParseName( cFilename )
   FOR nItem := 1 TO iMax
      cFileInfo := objFolder:GetDetailsOf( objFolderItem, nItem )
      cHeaderInfo := objFolder:GetDetailsOf( objFolder:Items, nItem )
      IF !EMPTY( cHeaderInfo ) .AND. !EMPTY( cFileInfo )
         AADD( aRet, { STRZERO( nItem, 3 ),;
                       TRIM( cHeaderInfo ),;
                       STRTRAN( TRIM( aData[ 2 ]  ), "?", "" ) } )
      ENDIF
   NEXT
   objShell := NIL

RETURN ACLONE( aRet ) 

who can help me please
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: FOR/NEXT into FOR EACH

Postby Antonio Linares » Tue Jan 03, 2023 7:05 am

Dear Jimmy,

It seems as you can't. Where do you get the 333 from ?
regards, saludos

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

Re: FOR/NEXT into FOR EACH

Postby Jimmy » Tue Jan 03, 2023 8:31 pm

hi Antonio,
Antonio Linares wrote:Where do you get the 333 from ?

i have found "somewhere" that Explorer can show uo to 329 Property of File ,,, so i use 333

---

i have ask ChatGPT for CODE (using Keywords) and got

Code: Select all  Expand view
* Create an instance of the Shell.Application object
oSA = CREATEOBJECT( "Shell.Application" )

* Get the current namespace
oNS = CREATEOBJECT( "Namespace" )
oDir = oSA.NameSpace( oNS )

* Set the directory path
cPath = "C:\Windows"
oDir = oSA.NameSpace( cPath )

* Set the file name
cFile = "test.txt"
oFile = oDir.ParseName( cFile )

* Get the number of properties
nCount = oDir.Count

* Iterate through the properties
FOR EACH oProp IN oDir
   * Get the property name
   cName = oDir.GetDetailsOf( oProp, 0 )
   ? cName + ": "

   * Get the property value
   cValue = oFile.GetDetailsOf( oProp, 0 )
   ? cValue
ENDFOR

after re-write OOP Syntax i try to run and got Error "Count" ... but i saw FOR EACH :idea:

---

so it was not my Idea which i try to get run
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Horizon and 40 guests