Alain da Silva Posted February 14, 2017 Report Share Posted February 14, 2017 bom dia, preciso copiar para um pendrive vários arquivos xml, porém precisa ser pela data do arquivo. Alguem tem uma rotina para isso. Outra coisa, depois de copiar o arquivo eu gostaria de mover os arquivos para outra pasta. obrigado Quote Link to comment Share on other sites More sharing options...
kapiaba Posted February 14, 2017 Report Share Posted February 14, 2017 Por data? Explique melhor. Quote Link to comment Share on other sites More sharing options...
aferra Posted February 14, 2017 Report Share Posted February 14, 2017 sem testar, mas acho que seria assim. aFile := Directory( <caminho_xml> + "*.XML" ) // retorno do directory //F_NAME, F_SIZE, F_DATE, F_TIME, F_ATTR aAnexos := {} AEval( aFile, {|a| IF( a[3] == <sua_variavel_validacao>, AAdd( aAnexos, a[1]), ) }) FOR x:=1 TO LEN(aAnexos) CopyFile( <caminho_xml> + aAnexos[x], <destino> + aAnexos[x], .T. ) //senão funcionar pode usar tb o COPY FILE <caminho_xml> + aAnexos[x] TO <destino> + aAnexos[x] NEXT quanto a move não conheço nenhuma função que faça isso pelo [x]Harbour. Quote Link to comment Share on other sites More sharing options...
kapiaba Posted February 14, 2017 Report Share Posted February 14, 2017 Seria isto mestre <Aferra>: ??? // Just for FW 32 bits #include "FiveWin.ch" #define FO_MOVE 0x0001 #define FO_COPY 0x0002 #define FO_DELETE 0x0003 #define FO_RENAME 0x0004 #define FOF_MULTIDESTFILES 0x0001 #define FOF_CONFIRMMOUSE 0x0002 #define FOF_SILENT 0x0004 // don't create progress/report #define FOF_RENAMEONCOLLISION 0x0008 #define FOF_NOCONFIRMATION 0x0010 // Don't prompt the user. #define FOF_WANTMAPPINGHANDLE 0x0020 // Fill in SHFILEOPSTRUCT.hNameMappings // Must be freed using SHFreeNameMappings #define FOF_ALLOWUNDO 0x0040 #define FOF_FILESONLY 0x0080 // on *.*, do only files #define FOF_SIMPLEPROGRESS 0x0100 // means don't show names of files #define FOF_NOCONFIRMMKDIR 0x0200 // don't confirm making any needed dirs #define FOF_NOERRORUI 0x0400 // don't put up error UI #define FOF_NOCOPYSECURITYATTRIBS 0x0800 // dont copy NT file Security Attributes #define FOF_NORECURSION 0x1000 // don't recurse into directories. static oDlg //----------------------------------------------------------------------------// function Main() DEFINE DIALOG oDlg TITLE "System Files management Dialogs" @ 0.5, 1 BUTTON "&Copy" ACTION CopyFile( "dlgfile.exe", "c:\dlgfile.exe" ) ; SIZE 30, 12 @ 1.5, 1 BUTTON "&Delete" ACTION DeleteFile( "c:\dlgfile.exe" ) ; SIZE 30, 12 @ 2.5, 1 BUTTON "&Move" ACTION MoveFile( "dlgfile.exe", "c:\dlgfile.exe" ) ; SIZE 30, 12 ACTIVATE DIALOG oDlg CENTERED return nil //----------------------------------------------------------------------------// function CopyFile( cSource, cDestination ) return SHFile( oDlg:hWnd, FO_COPY, cSource + Chr( 0 ), cDestination ) //----------------------------------------------------------------------------// function DeleteFile( cFileName ) return SHFile( oDlg:hWnd, FO_DELETE, cFileName + Chr( 0 ) ) //----------------------------------------------------------------------------// function MoveFile( cSource, cDestination ) return SHFile( oDlg:hWnd, FO_MOVE, cSource + Chr( 0 ), cDestination ) //----------------------------------------------------------------------------// #pragma BEGINDUMP #include <hbapi.h> #include <Windows.h> #include <ShellApi.h> #include <ShlObj.h> HB_FUNC( SHFILE ) { SHFILEOPSTRUCT sh; memset( ( char * ) &sh, 0, sizeof( sh ) ); sh.hwnd = ( HWND ) hb_parnl( 1 ); sh.wFunc = ( UINT ) hb_parnl( 2 ); sh.pFrom = ( LPSTR ) hb_parc( 3 ); sh.pTo = ( LPSTR ) hb_parc( 4 ); sh.fFlags = ( FILEOP_FLAGS ) hb_parnl( 5 ); hb_retnl( SHFileOperation( &sh ) ); } #pragma ENDDUMP //----------------------------------------------------------------------------// Quote Link to comment Share on other sites More sharing options...
Alain da Silva Posted February 14, 2017 Author Report Share Posted February 14, 2017 obrigado pela ajuda, copiar pela data da criação do arquivo. No caso do exemplo ai copiar somente os arquivos do dia 01/01/2017, porque pelo nome eu não saberia. nome data de modificação Tipo 35170262741319000125550010000322271000325137 01/01/2017 Documento Xml 35170262741319000125550010000322271000325137 01/01/2017 Documento Xml 35170262741319000125550010000322271000325137 02/01/2017 Documento Xml 35170262741319000125550010000322271000325137 03/01/2017 Documento Xml valeu Quote Link to comment Share on other sites More sharing options...
kapiaba Posted February 14, 2017 Report Share Posted February 14, 2017 Pare o AEVAL, com AAdd( aAnexos, a[3]) para ver se retorna a DATA do xml. Quote Link to comment Share on other sites More sharing options...
aferra Posted February 14, 2017 Report Share Posted February 14, 2017 Kapi essa é boa, não conhecia, alain não entendi, da forma que te passei é só vc realizar a verificação que necessita, sinceramente não entendi a sua frase. rsrs Quote Link to comment Share on other sites More sharing options...
Alain da Silva Posted February 14, 2017 Author Report Share Posted February 14, 2017 Td bem Alessandro, funcionou do jeito que vc passou, só estou tentando agora copiar para um pendrive. Teria como antes definir a pasta para onde gravar, como no cgetfile() ? Quote Link to comment Share on other sites More sharing options...
jfaguiar Posted February 14, 2017 Report Share Posted February 14, 2017 fiz assim: STATIC FUNCTION GeraZipXmlSat() LOCAL oDlg,nMONTH,nANO,cANO,cFOLDERSAT,aXMLSAT,oCbx LOCAL aMESES := {"Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"} dDATAF := DATE() nMONTH := MONTH(dDATAF) WHILE .T. -- dDATAF IF MONTH(dDATAF) # nMONTH EXIT ENDIF ENDDO nMES := MONTH(dDATAF) nANO := YEAR(dDATAF) cMES := aMESES[nMES] WHILE .T. DEFINE DIALOG oDlg FROM 5, 5 TO 22,60 TITLE 'Geração de Arquivo Xml Sat' oDlg:Cargo := .F. @ LINS(01.0),COLS(01) SAY "Informe o Mês Para Gerar:" @ LIND(02.0),COLD(01) COMBOBOX oCbx VAR cMES ITEMS aMESES SIZE 70,550 OF oDlg; STYLE CBS_DROPDOWN ; ON CHANGE ( nMES := oCbx:nAt,oCbx:Refresh() ) @ LINS(03.2),COLS(01) SAY "Informe o Ano:" @ LING(04.0),COLG(01) GET nANO PICT "9999" COLORS CLR_FONGET,CLR_FUNGET @ oDlg:nHeight()/2-19,oDlg:nWidth()/2-70 BTNBMP SIZE 30,15 Pixel; FILENAME "&cDRIVE\SISCOM\bitmaps\BTNOK.bmp"; ACTION (oDlg:Cargo := .T.,oDlg:End() ) @ oDlg:nHeight()/2-19,oDlg:nWidth()/2-35 BTNBMP SIZE 32,15 Pixel; FILENAME "&cDRIVE\SISCOM\bitmaps\BTNCANC.bmp"; ACTION oDlg:End() ACTIVATE DIALOG oDlg CENTERED SETKEY(VK_F3,{ }) IF !oDlg:Cargo .OR. nANO < 2016 EXIT ENDIF cANO := STR(nANO,4) dDATAI := "01/" + STRZERO(nMES,2) + "/" + RIGHT(cANO,2) dDATAI := CTOD(dDATAI) dDATAF := CHKPERIODO( dDATAI + 25,"F" ) // // Cria a pasta destino // cFOLDERSAT := "C:\SISCOM\XmlSat" + STRZERO(nMES,2) + cANO IF !lISDIR(cFOLDERSAT) lMkDir(cFOLDERSAT) ENDIF // // Busca os xmls na pasta onde eles estão // aXMLSAT := DIRECTORY("C:\SISCOM\CFe*.xml") lChDir(cFOLDERSAT) // Vou para a pasta dos arquivos xmls // // Copia somente os arquivos que estiverem no periodo especificados // FOR n := 1 TO LEN(aXMLSAT) dDATAXML := aXMLSAT[n,3] IF MONTH(dDATAXML) = nMES .AND. YEAR(dDATAXML) = nANO cARQXML := aXMLSAT[n,1] cDESTINO := cFOLDERSAT + "\" + cARQXML IF !FILE(cDESTINO) COPY FILE C:\SISCOM\&cARQXML TO &cDESTINO ENDIF ENDIF NEXT RELEASE aXMLSAT* // // Executa o winrar para compactar. No meu caso deixo na pasta \siscom\utilitarios // cComando := cDRIVE + "\Siscom\Utilitarios\Winrar A XmlSat" + STRZERO(nMES,2) + cANO + ".ZIP CFe*.xml" WinExec( cComando ) // // Inicio a rotina de e-mail para abrir o outlook e anexar o arquivo // cTXTEMAIL := "Bom dia" + chr(13)+chr(10) cTXTEMAIL += chr(13)+chr(10) cTXTEMAIL += "Segue anexo arquivo compactado com os arquivos xml do Cupom Fiscal" + chr(13)+chr(10) cTXTEMAIL += "Eletrônico da empresa Prolar Ref. "+STRZERO(nMES,2) +"/"+ cANO + chr(13)+chr(10) cTXTEMAIL += chr(13)+chr(10) cTXTEMAIL += "Obrigado "+chr(13)+chr(10) cSubject := "XmlSat Prolar " +STRZERO(nMES,2) +"/"+ cANO cRecipients := "contabilxxx@hotmail.com" cArq := cFOLDERSAT + "\XmlSat" + STRZERO(nMES,2) + cANO + ".ZIP" lChDir("C:\SISCOM") // retorno para a pasta do meu aplicativo Mmail( TRIM(cRecipients),,cSubject,cTXTEMAIL,cArq ) // Minha função de email ENDDO RETURN Nil ************************************************************************************** function Mmail(cTo,cSentBy,cEmailHeader,cEmailNotes,cANEXO1) oOutLook := TOleAuto():New("Outlook.Application") oMailItem := oOutLook:Invoke("CreateItem", 0) oMailitem:to:=cTo oMailitem:CC:= cSentBy oMailItem:Subject := cEmailHeader oMailItem:Body := cEmailNotes if ! empty(cANEXO1) IF VALTYPE(cANEXO1) == "C" oMailItem:Attachments:Add(cANEXO1) ELSEIF VALTYPE(cANEXO1) == "A" FOR _i := 1 TO LEN(cANEXO1) oMailItem:Attachments:Add( cANEXO1[_i] ) NEXT ENDIF endif oMailItem:display(.T.) RETURN(nil) ************************************************************************************ FUNCTION CHKPERIODO(dDATA,cOPC) LOCAL nMONTH := MONTH(dDATA) FOR nDAY = 1 TO 32 IF MONTH(dDATA) # nMONTH EXIT ENDIF IF cOPC == "F" ++ dDATA ELSE -- dDATA ENDIF NEXT IF cOPC == "F" RETURN(dDATA-1) ELSE RETURN(dDATA+1) ENDIF *************************************************************************** Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.