| 1. |
Solve : batch job to show files from network folders from today and yeasterday? |
|
Answer» Hi
C:\test>type yesterdayfiles.bat Code: [Select]@echo off for /f "delims=" %%i in ('cscript //nologo c:\test\evaluate.vbs "date -1"' ) do ( set yesterday=%%i ) for /f "tokens=1,2,3,4 delims=/ " %%a in ("%yesterday%") do set wday=null&set month=%%a&set day=%%b&set year=%%c if %month% LSS 10 set month=0%month% if %day% LSS 10 set day=0%day% set yesterday=%month%/%day%/%year% echo yesterday=%yesterday% set Today=%DATE% set Today=%DATE:~4,10% echo Today=%Today% dir /OD /A-D | findstr "%yesterday% %Today%" rem evaluate.vbs furnished by Salmon Trout rem evaluate.vbs rem Wscript.echo eval(WScript.Arguments(0)) Output: C:\test>yesterdayfiles.bat yesterday=06/08/2010 Today=06/09/2010 06/08/2010 02:46 AM 7 seq.txt 06/08/2010 07:04 PM 8 text1.txt 06/08/2010 07:04 PM 8 text2.txt 06/08/2010 07:04 PM 8 text3.txt 06/08/2010 07:37 PM 379 sw68.bat 06/08/2010 08:10 PM 10 text4.txt 06/08/2010 08:12 PM 339 sw268.bat 06/08/2010 08:59 PM 81 text.txt 06/08/2010 09:34 PM 323 sw4.bat 06/09/2010 08:14 AM 369 sw69.bat 06/09/2010 11:07 AM 184 yesterday.bat 06/09/2010 11:11 AM 3 filecount.txt 06/09/2010 01:11 PM 563 yesterdayfiles.bat C:\test>Hi Thank you very much for replay. I would like to ask you when I run it I have info: ------------------------------------------- yesterday=Input/Error:/Can Today=-06-10 2010-06-10 14:08 603 check files in ready_staying too long.bat ---------------------------- Do you know what can be the reason? I also do not know from where to take: evaluate.vbs - it is in your script. Many thanks for your replay BR RafalAlmost certainly something to do with the date format! Remove the @Echo Off from the top and the commands being processed will be SEEN, not just the error. Note that Marvin's example expects US date formats, you appear to be using military format - you will need to change the order of assignments of day, month and year values to match your locale GrahamQuote from: silberzin on June 02, 2010, 03:25:28 AM
Sib, Gpl is correct. We need the date format for files on your machine. cd to the directory you are working with. C:\>cd c:\test\ c:\test> Do a dir /OD *.xml and | pipe to more. Copy and paste part of that page here. For example: C:\test>dir /OD *.bat | more Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of C:\test 04/24/2010 02:39 PM 1,018 x.bat 04/24/2010 02:39 PM 1,018 buildlog.bat 04/24/2010 06:37 PM 199 matt.bat 04/25/2010 11:27 AM 260 matt5.bat 04/25/2010 11:27 AM 260 matt2.bat 04/25/2010 11:34 AM 307 matt3.bat 04/25/2010 11:41 AM 224 matt4.bat 04/25/2010 02:17 PM 125 ver61.bat 04/25/2010 02:33 PM 190 ver612.bat 04/25/2010 05:14 PM 235 helpme.bat 04/27/2010 12:06 PM 32 chtoE.bat 04/27/2010 07:33 PM 89 fil.bat 04/27/2010 09:52 PM 631 cmpfil.bat 04/27/2010 10:18 PM 698 cmplist.bat 05/05/2010 04:52 PM 192 filefromstr.bat 05/06/2010 12:37 PM 199 hannes.bat 05/06/2010 01:06 PM 194 erasedir.bat 05/07/2010 10:57 AM 229 sw57.bat 05/07/2010 02:16 PM 85 sw58.bat -- More -- also do an echo %DATE% c:\test>echo %DATE% Thu 06/10/2010 c:\test> Create a test directory and copy about 30 of the files you are concerned with. Don't run the code on the large folders until the code is working correctly. ( Forget the vbs code for finding yesterday's date. Enter yesterday's date manually until everything else works. We can find an easier way to find yesterday's date later. ( Or Salmon Trout might show you how to set up the vbs code later. )) Good LuckQuote from: silberzin on June 02, 2010, 03:25:28 AM
The copy and paste from the command window is different than from a web page or word processor. 1) Right click the bar in an open spot at the top just left of the red X. A dropdown MENU will indicate choices: Quote from: silberzin on June 10, 2010, 06:04:32 AM yesterday=Input/Error:/Can C:\test>type dayfiles.bat Code: [Select]@echo off rem dir /OD /A-D > dateformat.txt set Yesterday=2010-06-10 set Today=2010-06-11 echo Yesterday=%Yesterday% echo Today=%Today% findstr "%Yesterday% %Today%" dateformat.txt C:\test>dayfiles.bat Yesterday=2010-06-10 Today=2010-06-11 2010-06-10 12:17 PM 3,173 srcfiles.txt 2010-06-10 03:31 PM 2 bla.cfn 2010-06-11 03:48 AM 17 bla1.txt 2010-06-11 03:48 AM 16 bla2.txt 2010-06-11 01:37 PM 1,624 redirect.bat 2010-06-11 06:09 PM 413 sib611.bat 2010-06-11 06:24 PM 959 yesterdayfiles.bat C:\test>Quote from: silberzin on June 10, 2010, 06:04:32 AM
C:\test>type dayfiles.bat Code: [Select]@echo off rem This program will run automatically at 11:30pm everyday dir /OD /A-D > dateformat.txt dir /OD /A-D > Fdateformat.txt set /p Yesterday=<yesterday.txt for /f "tokens=1,2,3,4 delims=/ " %%a in ("%DATE%") do ( set wday=null&set month=%%b&set day=%%c&set year=%%d set Today=%month%/%day%/%year% set Ftoday=%year%-%month%-%day% ) echo Yesterday=%Yesterday% echo Today=%Today% echo Ftoday=%Ftoday% findstr "%Yesterday% %Today%" dateformat.txt rem echo %Today% > yesterday.txt rem remove "rem" when the program is set to run automatically at 11:30 pm Output: C:\test>dayfiles.bat Yesterday=06/11/2010 Today=06/12/2010 Ftoday=2010-06-12 06/11/2010 03:48 AM 17 bla1.txt 06/11/2010 03:48 AM 16 bla2.txt 06/11/2010 01:37 PM 1,624 redirect.bat 06/11/2010 06:09 PM 413 sib611.bat 06/11/2010 09:10 PM 285 trail.bat 06/11/2010 09:13 PM 39 filehel.txt 06/12/2010 07:23 PM 509 yesterdayfiles.bat 06/12/2010 07:33 PM 14 yesterday.txt 06/12/2010 08:01 PM 7,146 Fdateformat.txt 06/12/2010 08:06 PM 602 dayfiles.bat 06/12/2010 08:07 PM 0 dateformat.txt C:\test>Hi Thank you very much for all your replay. I have a filling that I am close to have solution but unfortunatelly I got lost Is possible for you to publish full code which I should use ?? We would like to schedule this code to be run automatic on one of my colleagues machine, therefore the best is if this program do not require any manual entry and show results on screen + create txt log. Hope that is possible to make Thank you in advance for help BR RafalQuote from: silberzin on June 14, 2010, 12:12:37 AM
I don't know the date format for your files. The following method for finding yesterday's date is not as good as the Salmon Trout method furnished above. But the vbs code was difficult to follow. C:\test>type fday.bat Code: [Select]@echo off echo 2010-06-13 > yesterday.txt rem remove above line after test phase dir /OD /A-D > dateformat.txt set /p Yesterday=<yesterday.txt for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do set wday=%%a&set month=%%b&set day=%%c&set year=%%d echo.Weekday: %wday% echo.Month : %month% echo.Day : %day% echo.Year : %year% set Today=%year%-%month%-%day% echo Yesterday=%Yesterday% echo Today=%Today% findstr "%Yesterday% %Today%" dateformat.txt echo %Today% > yesterday.txt rem only do the above at 11:30 pm Output: C:\test>fday.bat Weekday: Mon Month : 06 Day : 14 Year : 2010 Yesterday=2010-06-13 Today=2010-06-14 2010-06-13 07:23 PM 509 yesterdayfiles.bat 2010-06-13 10:10 PM 722 dayfiles.bat 2010-06-13 10:10 PM 7,146 Fdateformat.txt 2010-06-14 01:05 PM 448 fday.bat 2010-06-14 01:08 PM 10 yesterday.txt 2010-06-14 01:23 PM 0 dateformat.txt C:\test>Quote from: silberzin on June 14, 2010, 12:12:37 AM Is possible for you to publish full code which I should use? C:\test>schtasks /create /SC DAILY /TN test1 /TR c:\test\date.bat /ST 19:35 SUCCESS: The scheduled task "test1" has successfully been created. C:\test>type yesterday.txt The system cannot find the file specified. C:\test>type yesterday.txt 06/14/2010 C:\test>dir /OD yesterday.txt Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of C:\test 06/14/2010 07:35 PM 12 yesterday.txt 1 File(s) 12 bytes 0 Dir(s) 295,454,244,864 bytes free C:\test> Use 23:30 not 19:35 |
|