how to find the missing file by day of week in msdos

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
johnathan
Posts: 4
Joined: 25 Aug 2013 04:57

how to find the missing file by day of week in msdos

#1 Post by johnathan » 25 Aug 2013 05:54

hello everyone..

i am a new hand for batch scripting
please help me in this following issue

i have a folder,in it everyday i received a file which has same name but date is different,lik
sam.txt date modified-01/01/13(dd/mm/yy)
sam.txt date modified-02/01/13
.
.
.
sam.txt date modified-31/01/13


Now i want to check whether the file sam.txt is received on everyday or not, if not display the date and filename .. :?:

someone pls help me and sorry for my english..

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

Re: how to find the missing file by day of week in msdos

#2 Post by foxidrive » 25 Aug 2013 07:28

You can't have files in the same folder with the same name.

Can you explain a bit further?

johnathan
Posts: 4
Joined: 25 Aug 2013 04:57

Re: how to find the missing file by day of week in msdos

#3 Post by johnathan » 25 Aug 2013 08:49

yes,i am sorry

it's look lik

sam_010113.txt date modified-01/01/13(dd/mm/yy)
sam_010213.txt date modified-02/01/13
.
.
.
sam_013113.txt date modified-31/01/13

apacin_010113.txt date modified-01/01/13(dd/mm/yy)
apacin_010213.txt date modified-02/01/13
.
.
.
apacin_013113.txt date modified-31/01/13


like this everyday for january month a bunch of files is filled in the folder jan

now i hav a list of files(for eg.. sam,apacin,geon) and i wanna check everyday the files i listed is received or not..for example if sam_012813.txt is not received then it should get displayed with the date..

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

Re: how to find the missing file by day of week in msdos

#4 Post by foxidrive » 25 Aug 2013 09:27

Run this in the folder for January and test it - the batch file assumes that only sam_*.txt files exist or only apacin_*.txt files are in the folder, not a mixture of files.

You will have to be aware of which month you are testing and ignore the 31st day in months that only have 30 days, for example.

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /L %%a in (101,1,131) do (
set day=%%a
set day=!day:~-2!
dir /b *_??!day!??.txt 2>nul 1>&2
if errorlevel 1 echo day !day! is missing
)
pause

johnathan
Posts: 4
Joined: 25 Aug 2013 04:57

Re: how to find the missing file by day of week in msdos

#5 Post by johnathan » 25 Aug 2013 09:57

thanks will test it and let you know the result :)

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: how to find the missing file by day of week in msdos

#6 Post by Aacini » 25 Aug 2013 18:55

The Batch file below do what you want:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set i=100
for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do (
   set /A i+=1
   set daysPerMonth[!i:~-2!]=1%%a
)
set lastName=dummy_1231yy.txt
set lastDay=131
for %%a in (*.txt) do (
   set thisName=%%a
   set thisDay=1!thisName:~-8,2!
   set /A nextDay=lastDay+1, prevDay=thisDay-1
   if !thisDay! neq !nextDay! (
     if !thisDay! lss !lastDay! (
         rem Change in the month/name
         for /F %%m in ("!lastName:~-10,2!") do for /L %%d in (!nextDay!,1,!daysPerMonth[%%m]!) do (
            set auxDay=%%d
            echo !lastName:~0,-8!!auxDay:~-2!!lastName:~-6!
         )
         for /L %%d in (101,1,!prevDay!) do (
            set auxDay=%%d
            echo !thisName:~0,-8!!auxDay:~-2!!thisName:~-6!
         )
         set lastName=!thisName!
      ) else (
         rem Missed day(s) in same month
         for /L %%d in (!nextDay!,1,!prevDay!) do (
            set auxDay=%%d
            echo !thisName:~0,-8!!auxDay:~-2!!thisName:~-6!
         )
      )
   )
   set lastDay=!thisDay!
)

For example:

Code: Select all

C:> dir /b *.txt
apacin_020113.txt
apacin_020213.txt
apacin_020313.txt
apacin_020413.txt
apacin_020513.txt
apacin_020613.txt
apacin_020713.txt
apacin_020813.txt
apacin_020913.txt
apacin_021113.txt
apacin_021213.txt
apacin_021313.txt
apacin_021413.txt
apacin_021513.txt
apacin_021613.txt
apacin_021713.txt
apacin_021813.txt
apacin_021913.txt
apacin_022313.txt
apacin_022413.txt
apacin_022513.txt
apacin_022613.txt
apacin_022713.txt
sam_020213.txt
sam_020313.txt
sam_020413.txt
sam_020513.txt
sam_020613.txt
sam_020713.txt
sam_020813.txt
sam_020913.txt
sam_021113.txt
sam_021213.txt
sam_021313.txt
sam_021413.txt
sam_021513.txt
sam_021613.txt
sam_021713.txt
sam_021813.txt
sam_021913.txt
sam_022113.txt
sam_022213.txt
sam_022313.txt
sam_022413.txt
sam_022513.txt
sam_022613.txt
sam_022713.txt
sam_022813.txt

C:> test
apacin_021013.txt
apacin_022013.txt
apacin_022113.txt
apacin_022213.txt
apacin_022813.txt
sam_020113.txt
sam_021013.txt
sam_022013.txt


Antonio

johnathan
Posts: 4
Joined: 25 Aug 2013 04:57

Re: how to find the missing file by day of week in msdos

#7 Post by johnathan » 01 Sep 2013 07:10

THANKS A LOT :D
I HAVE CREATED A BATCH WHICH RUNS DAILY WILL SEPARATE THE FILE ACCORDING TO MY LIST IN DIFFERENT FOLDER..IS THERE ANY WAY TO HIDE THE PROMPT WHILE COPYING TAKE PLACE
EXAMPLE:
Overwrite C:\Users\bhaskasr\Desktop\DUMMY\chck.bat? (Yes/No/All): ALL
C:\Users\bhaskasr\Desktop\SCRIPTS\CHECKPRINT.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\CHECKPRINT.txt
C:\Users\bhaskasr\Desktop\SCRIPTS\CITI (2).BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\CITI.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\Create variables from date time batch - Script
Center - Spiceworks.htm
C:\Users\bhaskasr\Desktop\SCRIPTS\DELET.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\FD.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\mon.bat
C:\Users\bhaskasr\Desktop\SCRIPTS\reference script.txt
C:\Users\bhaskasr\Desktop\SCRIPTS\SPLITDATE.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\SRCH.BAT
C:\Users\bhaskasr\Desktop\SCRIPTS\timst.bat
C:\Users\bhaskasr\Desktop\SCRIPTS\ts.bat
C:\Users\bhaskasr\Desktop\SCRIPTS\WELCOME.BAT
15 file(s) copied.

I DON'T WANT TO SEE THIS PROMPT WHILE COPYING BUNCH OF FILES....
CAN U HELP IN THIS ..I SEARCHED IN GOOGLE BUT STILL COULDN'T FIX THIS..

ONCE AGAIN THANKS A LOT FOR SHARING YOUR KNOWLEDGE,THIS REALLY MAKES ME TO LOVE SCRIPTING NOW A DAYS..AND IF U DON'T MIND PLEASE EXPLAIN WHAT EXACTILY THE COMMAND DO IN UR LAST POST..

Post Reply