Copy /pack files with same part of name...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bartlo
Posts: 6
Joined: 21 Apr 2013 06:01

Copy /pack files with same part of name...

#1 Post by bartlo » 21 Apr 2013 06:13

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy /pack files with same part of name...

#2 Post by foxidrive » 21 Apr 2013 09:10

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?

bartlo
Posts: 6
Joined: 21 Apr 2013 06:01

Re: Copy /pack files with same part of name...

#3 Post by bartlo » 21 Apr 2013 12:01

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

bartlo
Posts: 6
Joined: 21 Apr 2013 06:01

Re: Copy /pack files with same part of name...

#4 Post by bartlo » 21 Apr 2013 13:12

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 !!!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy /pack files with same part of name...

#5 Post by foxidrive » 22 Apr 2013 00:29

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.

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

bartlo
Posts: 6
Joined: 21 Apr 2013 06:01

Re: Copy /pack files with same part of name...

#6 Post by bartlo » 22 Apr 2013 02:20

Thank you

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy /pack files with same part of name...

#7 Post by foxidrive » 22 Apr 2013 03:17

Try the code above in my post again - I edited it.

Another change is that if enter alone is pressed then it will quit.

bartlo
Posts: 6
Joined: 21 Apr 2013 06:01

Re: Copy /pack files with same part of name...

#8 Post by bartlo » 02 May 2013 01:36

It is working perfectly - THANK YOU !!!

Post Reply