Jump to content
Fivewin Brasil

COMO COMPACTAR E DESCOMPARTAR ARQUIVOS QUE ESTÃO NO DIRETÓRIO PRINCIPAL E NOS SUB-DIRETÓRIOS


edmandc

Recommended Posts

A compactação está ok!

Não estou conseguindo descompactar nos respectivos diretórios

- Segue arquivo de definições e código

arquivo memo (backup.lst) contendo quais arquivos serão comprimidos:

*.cus
*.dat
*.dbf
*.dbt
*.mpr
*.rlt
*.rlc
*.fpt
*.rel
*.sys
IMAGENS\IMGPLAN\*.*

 

código:

*************************************************
* COPIASEG.PRG - GERA E RESTAURA BACKUPS        *
* CHAMADA DE MENUPRIN.PRG - A.PRG E AJUSTVER.PRG*
*************************************************

#include "fivewin.ch"
#include "directry.ch"
#include "constant.ch"

***********************
function copiaseg(modo)
***********************
local carqbkp,clistabkp,carquivos,nitem,narea,aarquivos

local c_path2 := ''
local c_path3 := ''
priva cdirlocal := cfilepath( getmodulefilename( getinstance() ) )
priva afiles   := {}
priva anomarqs := {}
priva arbck    := {}
priva ctarqbkp,clocalbkp,carqbkp1,carqbkp2,carqbkp3

set date brit

* Como nao e possível criar nomes de arquivos com ':' nem com '/' trocar estes caracteres por '-'
  if modo == 'ajustver'
     carqbkp1 := 'copseg ' + dtoc(date()) + ' ' + time() + '.zip'
  else
     carqbkp1 := 'copseg ' + dtoc(diatual) + ' ' + time() + '.zip'
  endif

  carqbkp2 := strtran( carqbkp1, ":","-" )
  carqbkp3 := strtran( carqbkp2, "/","-" )

if modo == 'ajustver'
   diatual := date()
   clocalbkp :=  diskname() + ':\' + curdir() + '\BACKUPS\'
else
   if cfglocbkp # 1
      clocalbkp := cfgexpbkp
   else
      clocalbkp :=  diskname() + ':\' + curdir() + '\BACKUPS\'
   endif
endif

carqbkp   := clocalbkp + carqbkp3

c_path2   := diskname()+ ':\' + curdir()  + '\'

clistabkp := memoread("backup.lst")

for nitem := 1 to mlcount(clistabkp)
   carquivos := memoline(clistabkp,,nitem)

   aFiles   := directory(c_path2+carquivos)

   for i=1 to len(afiles)
     aadd( arbck , c_path2+afiles[i,1] )
   next

   for i =1 to len(arbck)
      aadd(anomarqs, arbck )
   next

next

c_path3  := diskname()+ ':\' + curdir()  + '\imagens\imgplan\'
aFiles   := Directory( c_path3 + '*.*' )
for i=1 to len(afiles)
  aadd(arbck, c_path3+afiles[i,1] )
next

for i =1 to len(arbck)
   aadd(anomarqs,arbck)
next


if modo == 'gerar' .or. modo == 'ajustver'

   if comprime( carqbkp, anomarqs )
      retu .t.
   endif

else

   descomprime()

endif
retu nil

*********************************
stat func comprime(carqbkp,afile)
*********************************
local odlg,ometer,otext,cmsg,nlen,lval,nactual:=0

nlen:=len(afile)

//aeval( directory('*.cdx'), {|arq_dele| ferase( arq_dele[1] )} )

define dialog odlg from 1, 1 to 12, 62 title "Aguarde... comprimindo arquivos..."

   @ 0.5, 2 say otext var cmsg size 180, 20 of odlg
   @ 2  , 2 meter ometer var nactual total 100 of odlg size 200, 20

 // Sintaxe zip
//hb_ZipFile( <cFile>, <cFileToCompress> | <aFiles>, <nLevel>, <bBlock>, <lOverWrite>, <cPassword>, <lWithPath>, <lWithDrive>, <pFileProgress>) --> lCompress

   odlg:bstart:={||lval := hb_zipfile( carqbkp, afile, 9, {|carqbkp,npos|otext:settext('Comprimindo '+carqbkp),;
                                                         nactual:=npos/nlen*100,ometer:set(nactual)},,,.t.,.t. ),;
                   if( lval, msginfo('O arquivo de cópia de segurança foi gerado com sucesso!' +CRLF+CRLF+;
                                     'Nome do Arquivo: ' + carqbkp3   +CRLF+CRLF +;
                                     'Localizado   em: ' + clocalbkp  +CRLF+CRLF+;
                                     'GRAVE O ARQUIVO GERADO EM UM OUTRO LOCAL','Atenção!'),;
                                     msgstop('Não foi possível realizar a compressão dos arquivos!')),;
                   odlg:end() }


activate dialog odlg centered //       on paint poenotopo(odlg)

retu lval

***************************
static function descomprime
***************************
local odlg

define dialog odlg;
       resource 'RCANCCONTI';
       font ofntprinc;
       color cor_pret,cor_azulff

       redefine say id 1000 of odlg color cor_azul,cor_azulff
       redefine say id 1001 of odlg color cor_verm,cor_azulff
       redefine say id 1002 of odlg color cor_verm,cor_azulff
       redefine say id 1003 of odlg color cor_verm,cor_azulff
       redefine say id 1004 of odlg color cor_verm,cor_azulff
       redefine say id 1005 of odlg color cor_verm,cor_azulff

       redefine button id 2000;
                of odlg;
                action (frestaura(odlg),odlg:end())

       redefine button id 3000;
                of odlg;
                action odlg:end()

       odlg:lhelpicon := .f.

activate dialog odlg centered

retu nil

**************************
stat func frestaura(vtela)
**************************
local odlg,nfiles,otext, cmsg, ometer,nactual:=0,carqbkp

vtela:hide()

carqbkp :=  cGetFile( "Arq de Backup (*.zip)| *.zip|" ,"Selecione o arquivo de cópia de segurança!", 4,clocalbkp )

if empty( carqbkp ) .and. !file( carqbkp )
   msgalert('Não foi realizada a restauração dos arquivos da cópia de segurança!','Atenção!')
   retu nil
endif

anomarqs := hb_getfilesinzip(carqbkp,.t.)

anom:={}

for i =1 to len(anomarqs)
   aadd( anom,  diskname()+':\'+ upper(anomarqs[1]) )
next

nfiles   := len(anom)

define dialog odlg from 1, 1 to 10, 60 title "Aguarde... Recuperando dados..."

       @ 0.5, 2 say otext var cmsg size 180, 20 of odlg
       @ 2  , 2 meter ometer var nactual total 100 of odlg size 200, 20

      

 odlg:bstart := {|| lval := hb_unzipfile( carqbkp,;
                                 { |carqbkp,nposi| otext:settext('Descomprimindo'+CRLF+carqbkp),nactual:=nposi/nfiles*100,ometer:set(nactual)};
                                   ,,,,anom ),;
                       if( lval,;
                           if(reorgsys('restbkp'),;
                                  (msginfo('Restauração realizada com exito!'+CRLF+CRLF,'Atenção!'),odlg:end()),;
                                  (msgstop('Não foi possível restaurar os dados da cópia de segurança!'),odlg:end() )),;
                             (msgstop('Não foi possível restaurar os dados da cópia de segurança!'),odlg:end() ))}


       odlg:lhelpicon := .f.

activate dialog odlg centered

vtela:show()

retu nil
 

 

Link to comment
Share on other sites

RESOLVIDO...

Estava errado o trecho:

 odlg:bstart := {|| lval := hb_unzipfile( carqbkp,;
                                 { | carqbkp , nposi| otext:settext('Descomprimindo'+CRLF+carqbkp),nactual:=nposi/nfiles*100,ometer:set(nactual)};
                                   ,,,,anom ).

o certo é

 odlg:bstart := {|| lval := hb_unzipfile( carqbkp,;
                                 { | anom ,nposi| otext:settext('Descomprimindo'+CRLF+carqbkp),nactual:=nposi/nfiles*100,ometer:set(nactual)};
                                   ,,,,anom )

obrigado e excelente ano à todos.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...