FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DirectoryRecurse
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

DirectoryRecurse

Posted: Wed Oct 13, 2021 06:04 AM

DirectoryRecurse

Function DirectoryRecurse change current directory

https://xharbour-developers.narkive.com ... -directory

Hello friends,
I put this here in case someone notices the same problem.
I had this behaviour yesterday on a Windows 2019 server.

Best regards,
Otto

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM

Re: DirectoryRecurse

Posted: Wed Oct 13, 2021 11:49 AM
Simples,

Code (fw): Select all Collapse
   // Saber onde esta o executavel
   cDirExe := cFILEPATH(GETMODULEFILENAME(GETINSTANCE()))

FUNCTION EXCLUIR_PDFS_UNIDANFE( oMeter, oText, oDlg, lEnd )

   LOCAL cPath, cChave, cNfeExcluir, cPdfExcluir, cFileNfe, cFilePdf

   SELECT CADNFE

   IF CADPARAM->TPAMB = [1]  // em producao
      SET ORDER TO 03
   ELSE
      SET ORDER TO 01
   ENDIF

   GO TOP

   oMeter:nTotal := RecCount()

   oMeter:Refresh()

   oText:SetText( "Aguarde, Procurando Arquivos..." )

   wContador := 0

   WHILE .NOT. EOF()

      // caminho do diretorio
      cPath := cDirExe+"UNIDANFE\EMAIL\ANEXOS\"

      // Chave para pegar o .PDF e o .XML - Exemplo
      //cChave := "35130144363265000120550000008000201008000200"
      cChave := CADNFE->CHAVEACES

      cFileNfe := ALLTRIM( cCHAVE ) + "nfe.xml"     // EXCLUSAO DO .XML

      cNfeExcluir := DIRECTORYRECURSE( cPath + cFileNfe )

      cFilePdf := ALLTRIM( cCHAVE ) + "-danfe.pdf"  // EXCLUSAO DO .PDF

      cPdfExcluir := DIRECTORYRECURSE( cPath + cFilePdf )

      IF LEN( cPdfExcluir ) == 0 .AND. LEN( cNfeExcluir ) == 0

         // NADA A FAZER
         oText:SetText( "Nenhum Arquivo Encontrado..." )

         CONTINUE

      // ARQUIVO ENCONTRADO EM: C:\INST_NFE\UNIDANFE\EMAIL\ANEXOS\varios subdir
      ELSE 

         cArq := ""
         cExt := ""
         cPat := ""

         FOR nI = 1 to LEN(cPdfExcluir)

            hb_FNameSplit( cPdfExcluir[nI,1], @cPat, @cArq, @cExt )

            wContador = wContador + 1

         NEXT

         cPdfExcluirs := ALLTRIM( cPat+cArq+cExt )

         DELETEFILE( cPdfExcluirs )

         FOR nI = 1 to LEN(cNfeExcluir)

            hb_FNameSplit( cNfeExcluir[nI,1], @cPat, @cArq, @cExt )

            wContador = wContador + 1

         NEXT

         cNfeExcluirs := ALLTRIM( cPat+cArq+cExt )

         DELETEFILE( cNfeExcluirs )

      ENDIF

      SKIP

      oText:SetText( "Eliminado Arquivo(s):  "        +               ;
                      Alltrim( STR( wContador, 6, 0 ) ) + "  de:  " + ;
                      Alltrim( STR( WContador, 6, 0 ) )  + ", Aguarde..." )

      oMeter:Set( RecNo() )

      SYSREFRESH()

   ENDDO

   GO TOP

   MsgInfo( OemToAnsi( "PRONTO! ROTINA COMPLETADA COM SUCESSO" )+CRLF+ ;
            OemToAnsi( "TECLE <ENTER> PARA CONTINUAR...      " ),      ;
            OemToAnsi( "Rotina Completada com Sucesso...     " ) )

RETURN NIL


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

Re: DirectoryRecurse

Posted: Wed Oct 13, 2021 01:35 PM

João, Thank you.
I will test your function.

Best regards,
Otto

Continue the discussion