Batch Script to Select Files by Data

Asked

Viewed 552 times

1

I would like to create a Batch script that scans inside a folder and its sub-folders, finding the XML files and placing them in a temporary folder. So that later, I can compress using 7-Zip.

Below follows script using Winrar, but wanted to do without using a program and yes commands.

@echo off
:: a adicionar ficheiros para um arquivo
::-ep excluir caminho nos nomes
::r reparar arquivo danificado
::-ta<date> processar arquivos informados apos a data fornecida
::-tb<date> processar arquivos informados anterior a data fornecida
echo Informe os dados corretamente.
echo #######################
set LOCAL_XML=C:\Fashion 2.0\nfce\arquivos\assinado\*.XML
set LOCAL_XML_2=C:\Fashion 2.0\nfe\arquivos\assinado\*.XML
SET LOCAL_BACKUP="D:\Documentos\Desktop\Shopsync"
SET ZIPADOR=C:\Program Files\WinRAR\WINRAR.EXE
del *.zip
echo Digite o Ano:
SET /p ANO=
echo Digite o Mes:
SET /p MES=
echo Digite a Data Inicial:
SET /p DIA_INICIAL=
echo Digite a Data Final:
SET /p DIA_FINAL=
echo Aguarde gerando arquivo compactado...

CD 
"%ZIPADOR%" a -ep -r -ta%ANO%%MES%%DIA_INICIAL% -tb%ANO%%MES%%DIA_FINAL%235959 %LOCAL_BACKUP%\vendas%ANO%%MES%%DIA_INICIAL%" a "%ANO%%MES%%DIA_FINAL%.zip "%LOCAL_XML%"
"%ZIPADOR%" a -ep -r -ta%ANO%%MES%%DIA_INICIAL% -tb%ANO%%MES%%DIA_FINAL%235959 %LOCAL_BACKUP%\vendas%ANO%%MES%%DIA_INICIAL%" a "%ANO%%MES%%DIA_FINAL%.zip "%LOCAL_XML_2%"

1 answer

1


inserir a descrição da imagem aqui


@echo off & setlocal enableextensions enabledelayedexpansion & title <nul

mode 79,10 & color 0a & title Q38135.cmd

set "_bck=D:\Documentos\Desktop\Shopsync"
set "_Zip=C:\Program Files\WinRAR\Rar.exe"

set "_xml=C:\Fashion 2.0\nfce\arquivos\assinado" 
set "_xml="!_xml!","C:\Fashion 2.0\nfe\arquivos\assinado""
set "_ptp="%__APPDIR__%\pathping.exe" 127.1 -n -q 1 -p 40""

call :^) && for /l %%l in (1 2 70)do cls & echo=!_lf! && if not "%%l" == "70" ( 
  echo/ & echo= !_ul:~-%%l! & echo= !_ban:~-%%l! & echo= !_ul:~-%%l! & echo/
  echo= !_lf! &!_ptp! 2>nul >nul) else echo/ !_ul! & echo= !_ban! & echo=!_ul!

cd /d "!_bck!" & for %%s in (ini,fim)do set/p "_%%~s=!_msn!" && call :^[ "!_%%~s!" "%%~s"
set "_tag=-ta!_ini:/=!000000 -tb!_fim:/=!235959" & set "_bck=!_bck!\Vendas_!_fim:/=-!_Final.Rar" && (
for %%x in (!_xml!)do title .: Backup NFCe/NFe ^| "%%~x" Gerando Arquivo "!_fim:/=!_Final.Rar" :.&& (
  "!_zip!" a -ep -r !_tag! "!_bck!" "%%~x\*.xml" && echo/ Backup efetuado^!!)) & endlocal & goto :^V

:^)
:: seta variaveis para uso na interface de comando ::
set "_msn= Informe data inicial com o formato AAAA/MM/DD: " && set _lf=^

<nul 2>nul & cmd /v/c set "_lf=!_lf!^!_lf!"
>nul set "_ul=------------------------------------------------------------------ "
>nul set _ban=^
    ----- * B A C K - U P :  N F C e  ^&  N F e / X M L * ----- && exit /b

:^[
set "_msn=!_msn:data inicial=a data final!" & set "_str=%~1"
for /f %%s in ('cmd /u/c set /p "=%_str: =%"^<nul^|find /v /c ""')do set "_cnt=%%s"
for /f %%s in ('cmd /u/c set /p "=%_str: =%"^<nul^|find /c "/"')do set "_bar=%%s"
set /a "_num=!_cnt!-!_bar!" & for %%i in (cnt-10,bar-2,num-8)do for /f "tokens=1,2delims=-" %%A in ('
echo=%%i')do if not "!_%%A!"=="%%B" (for /l %%L in (1 1 4)do if "%%L"=="4" (echo/ ERRO: Data Informada %~1: 
     endlocal & timeout -1 2>nul & call "%~f0" & exit /b) else set "_msn=!_msn:data inicial=a data final!"
     )
set "_str=" & exit /b

:^V

Browser other questions tagged

You are not signed in. Login or sign up in order to post.