Moving files based on creation date of parent file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Guest

Moving files based on creation date of parent file

#1 Post by Guest » 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: Select all

** 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]

CameronY
Posts: 1
Joined: 09 May 2006 04:06
Location: Brisbane, Australia

Above post

#2 Post by CameronY » 09 May 2006 04:34

Was me :wink:
Didn't realise that I wasn't logged in.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#3 Post by DosItHelp » 10 May 2006 21:56

CameronY

Very Interesting ...

Add the following function at the end of your batch:

Code: Select all

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: Select all

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:

Ed Diarrhea
Posts: 6
Joined: 01 Jul 2011 16:38

Re: Moving files based on creation date of parent file

#4 Post by Ed Diarrhea » 13 Jul 2011 09:00

Sie sehen aus wie bitte helfen sie verstehen nicht, was war der einsatz

Post Reply