DosTips.com

A Forum all about DOS Batch
It is currently 03 Dec 2015 00:47

All times are UTC-06:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 09 May 2006 04:12 
Hi all,

Have been trying in vain to script the following and I'm running short of patience trying to work a solution.

The problem...
In the directory ~\Pending\ are the following files...
2C5F8R
2D4AIX
2DPHF4
2DQOMS
2DT2CL
2DZL2J [...plus another +1200 more]

In another directory ~\Unprocessed\?????????\ are files with the naming convention of:
XXXXXX_yyyymmddHHMMSS_duplicate [...there are thousands of them]

Where:
XXXXXX is reflective of the name found in the ~\Pending\ directory.
yyyymmddHHMMS is reflective of the creation time stamp of this file.
????????? is the office ID entered by user.

What is to be accomplished is the following ...
1) Identify in the Pending directory files for a specific office ID
2) Identify in the Unprocessed directory duplicate files for specific office ID that are duplicated (easy as the office ID is directory and duplicate will be in the file name)
3) Do some database updates
4) Move the files found in step 1 to the main download directory so that they can be reprocessed
5) Move the files found in step 2 to the main download directory so that they can be reprocessed if there was a matching files (XXXXXX) in the Pending directory and the date created is after the date created for the file in the Pending directory.

Have been trying to work this out for the last four days and sadly getting no where fast. And I don't wish it upon anyone to do this task manually (!!). It's step five that is causing the biggest headache for me.

Any help is appreciated.

- - - - - - - - - - - - - - - - - - - - - - - - - - -

Sample data would be the following ...
Code:
** OID   = AKLPI3503    (Entered by user)
** Pending File = 2DQOMS   ( dir /tc /-c 2DQOMS* )

05/04/2006  10:38              725 2DQOMS

** Checking for 2DQOMS related items in ~\UnProcessed\?????????\ ..   ( dir /tc /-c 2DQOMS* )

05/04/2006  10:35             2200 2DQOMS_20060405114049_duplicate
05/04/2006  11:49             2005 2DQOMS_20060405114931_duplicate
06/04/2006  10:21              383 2DQOMS_20060406102111_duplicate[[/size]


Top
   
 Post subject: Above post
PostPosted: 09 May 2006 04:34 
Offline

Joined: 09 May 2006 04:06
Posts: 1
Location: Brisbane, Australia
Was me :wink:
Didn't realise that I wasn't logged in.


Top
   
 Post subject:
PostPosted: 10 May 2006 21:56 
Offline
Expert

Joined: 18 Feb 2006 19:54
Posts: 235
CameronY

Very Interesting ...

Add the following function at the end of your batch:

Code:
GOTO:EOF

:CmpFTime op file1 file2 attr1 attr2 -- compares the time of two files
::                  -- op    [in]     - compare operator, see 'IF /?', i.e.EQU, NEQ, LSS, LEQ, GTR, GEQ
::                  -- fileL [in]     - file name, left side of compare
::                  -- file2 [in]     - file name, right side of compare
::                  -- attrL [in,opt] - time field to be used for fileL, see 'dir /?', i.e. /tc, /ta, /tw, default is /tw
::                  -- attrR [in,opt] - time field to be used for fileR, default is attrL
SETLOCAL
set op=%~1
set fileL=%~2
set fileR=%~3
set attrL=%~4
set attrR=%~5
if "%op%"=="" set op===
if "%attrL%"=="" set attrL=/tw
if "%attrR%"=="" set attrR=%attrL%
for /f "tokens=1-6 delims=/: " %%a in ('"dir %attrL% /-c "%fileL%"|findstr "^^[0-1]""') do (
    set TL=%%c%%a%%b%%f%%d%%e
)
for /f "tokens=1-6 delims=/: " %%a in ('"dir %attrR% /-c "%fileR%"|findstr "^^[0-1]""') do (
    set TR=%%c%%a%%b%%f%%d%%e
)
if "%TL%" %op% "%TR%" (rem.) ELSE set=2>NUL
EXIT /b %ERRORLEVEL%


The "for" statement will convert a line like this:
05/04/2006 11:49 AM 2200 2DQOMS_20060405114049_duplicate
to:
20060110AM0357
Having now strings encoding the file time, we can subsequently compare the strings using the operator "op" passed into the function.
The (rem.) will make the function succeed, the set=2>NUL will make the function fail. (little trick)

In your main batch you should be able to do something simple like the following:
Code:
set PFile=2DQOMS
for %%a in ('"dir /b %PFile%*"') do (
    CALL:CmpFTime LSS "~\Pending\%PFile%" "%%~fa" /tc &&(
        copy "%%~fa" "download-directory"
    )
)

... whereas the copy will only be executed when the function succeeds, or so to say: when the compare returns TRUE.

DOS IT HELP? :wink:


Top
   
PostPosted: 13 Jul 2011 09:00 
Offline

Joined: 01 Jul 2011 16:38
Posts: 6
Sie sehen aus wie bitte helfen sie verstehen nicht, was war der einsatz


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited