DirectoryRecurse

DirectoryRecurse

Postby Otto » Wed Oct 13, 2021 6: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: DirectoryRecurse

Postby karinha » Wed Oct 13, 2021 11:49 am

Simples,

Code: Select all  Expand view  RUN

   // 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
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: DirectoryRecurse

Postby Otto » Wed Oct 13, 2021 1:35 pm

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


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 112 guests