Hello
Could you please support me with such problem:
I hane in one catalogue lots of files with date in name format like myname20130421_1426.xml ( those files are generated automaticly in random time however during a day it is over 300 new)
I want to make script that:
1) script is asking " echo "Give me date"
2) after giving a date with format "20130421" scrpit will pack files *20130421*.xml to one file .zip
3) send this file to FTP or mail
I found some scropts to use xcopy or robocopy or copy to do it, however I dont know How to wrote the script that will ask about part of file name/date ( to filter it) and then put it into copy command ( or better pack to zip command)
Also some info if user give wrong file name (only numbers - this date format)
could you please support me ?
Thanks in advance
Regards Bartek
Copy /pack files with same part of name...
Moderator: DosItHelp
Re: Copy /pack files with same part of name...
There is a batch script to email and it can attach files, so that part is easy.
My questions are:
1) You want to input a date and pack the files up - but do you want the files deleted once they are archived, or not?
2) Do you want to use 7-Zip to pack the files?
3) What sort of error checking do you need? If the entered date matches no files, then inform the user and ask for another date?
My questions are:
1) You want to input a date and pack the files up - but do you want the files deleted once they are archived, or not?
2) Do you want to use 7-Zip to pack the files?
3) What sort of error checking do you need? If the entered date matches no files, then inform the user and ask for another date?
Re: Copy /pack files with same part of name...
Thank you for answer
1) original files should stay
2) I can use 7zip or pkzip it doean`t matter once it is free software
3) yes - it can ask for next one date
Best regards
Bartek
1) original files should stay
2) I can use 7zip or pkzip it doean`t matter once it is free software
3) yes - it can ask for next one date
Best regards
Bartek
Re: Copy /pack files with same part of name...
Already have this:
@echo off & setlocal enableextensions
set /P file="Enter date to export:"
7z a archive%file%.zip e:\1111\*%file%*.xml
Echo %file%
:END
exit
now need somethink to:
1) secure user to not enter for example "1" or "*" on the date ( it will compress all files - I need only files with specyfied date "20130429"
2) email this zipped file
Thank for you time !!!
@echo off & setlocal enableextensions
set /P file="Enter date to export:"
7z a archive%file%.zip e:\1111\*%file%*.xml
Echo %file%
:END
exit
now need somethink to:
1) secure user to not enter for example "1" or "*" on the date ( it will compress all files - I need only files with specyfied date "20130429"
2) email this zipped file
Thank for you time !!!
Re: Copy /pack files with same part of name...
Test this: I removed the leading * in *%file%*.xml as you said you only need to match the start of the filename.
I edited this - I had typo'd the closing % characters.
I edited this - I had typo'd the closing % characters.
Code: Select all
@echo off & setlocal enableextensions
:loop
set "file="
set /P "file=Enter date to export: "
if not defined file goto :EOF
rem get new input if more than 8 characters
if not "%file:~8,1%"=="" goto :loop
rem get new input if less than 8 characters
if "%file:~7,1%"=="" goto :loop
rem check for only numbers
for /f "delims=1234567890" %%a in ("%file%") do goto :loop
7z a archive%file%.zip e:\1111\%file%*.xml
Echo %file%
:END
exit
Re: Copy /pack files with same part of name...
Thank you
it doesn`t work ( I change :loop place and cuted lenght check so is ok now)
it doesn`t work ( I change :loop place and cuted lenght check so is ok now)
Code: Select all
@echo off & setlocal enableextensions
set "file="
set /P "file=Enter date to export: "
:checknumbers
echo check for only numbers
set "file="
set /P "file=Enter date to export: "
for /f "delims=1234567890" %%a in ("%file%") do goto :checknumbers
7z a archive%file%.zip e:\1111\%file%*.xml
Echo %file%
:END
pause
Re: Copy /pack files with same part of name...
Try the code above in my post again - I edited it.
Another change is that if enter alone is pressed then it will quit.
Another change is that if enter alone is pressed then it will quit.
Re: Copy /pack files with same part of name...
It is working perfectly - THANK YOU !!!