' DSC2REN(1.1)  Convert DESCRIPT.ION into Rename BAT   06/17/2005-07/14/2005
' --------------------------------------------------------------------------
' Copyright (C) 2005 by Vladimir Veytsel                       www.davar.net

' Type ---------------------------------------------------------------------

'    Procedure

' Parameters ---------------------------------------------------------------

'    None - just run it in the current directory of DESCRIPT.ION file created
'    by RENPHOT and maintained by ACDSee.  As a result the REN-LFN.BAT file
'    will be generated in the same directory.  Then run REN-LFN.BAT in Windows
'    Command session (not DOS!) to rename 8.3 photo image files into LFNs 
'    generated from DESCRIPT.ION file.

'    Notes:

'     - Program is designed to work on combined directories intended for data
'       exchange.  Combine them using ACDSee or 4DOS COPY command to handle
'       DESCRIPT.ION files.

'     - To have a way back a REN-8-3.BAT file gets generated in the current
'       directory.  It can be used to reverse LFNs to the original 8.3 names.

'     - The situation when more than one picture was taken in the span of
'       only one minute is taken care of.

' Example ------------------------------------------------------------------

'  - Directory DESCRIPT.ION File

'    04211011.JPG Sun 04/21/2002 10:11  Harriman State Park, NY
'    04231927.JPG Tue 04/23/2002 19:27  Park Ave, NYC
'    04271658.JPG Sat 04/27/2002 16:58  Ridgewood, NJ
'    04271659.JPG Sat 04/27/2002 16:59  Ridgewood, NJ
'    04271660.JPG Sat 04/27/2002 16:59  Ridgewood, NJ
'    04271661.JPG Sat 04/27/2002 16:59  Ridgewood, NJ
'    05012343.JPG Wed 05/01/2002 23:43  Ridgewood, NJ

'  - Generated REN-LFN.BAT File

'    REN 04211011.JPG 2002-04-21_Sun_10-11_Harriman_State_Park_NY.jpg
'    REN 04231927.JPG 2002-04-23_Tue_19-27_Park_Ave_NYC.jpg
'    REN 04271658.JPG 2002-04-27_Sat_16-58_Ridgewood_NJ.jpg
'    REN 04271659.JPG 2002-04-27_Sat_16-59_Ridgewood_NJ.jpg
'    REN 04271660.JPG 2002-04-27_Sat_16-59_1_Ridgewood_NJ.jpg
'    REN 04271661.JPG 2002-04-27_Sat_16-59_2_Ridgewood_NJ.jpg
'    REN 05012343.JPG 2002-05-01_Wed_23-43_Ridgewood_NJ.jpg

'  - Generated REN-8-3.BAT File

'    REN 2002-04-21_Sun_10-11_Harriman_State_Park_NY.jpg 04211011.JPG
'    REN 2002-04-23_Tue_19-27_Park_Ave_NYC.jpg 04231927.JPG
'    REN 2002-04-27_Sat_16-58_Ridgewood_NJ.jpg 04271658.JPG
'    REN 2002-04-27_Sat_16-59_Ridgewood_NJ.jpg 04271659.JPG
'    REN 2002-04-27_Sat_16-59_1_Ridgewood_NJ.jpg 04271660.JPG
'    REN 2002-04-27_Sat_16-59_2_Ridgewood_NJ.jpg 04271661.JPG
'    REN 2002-05-01_Wed_23-43_Ridgewood_NJ.jpg 05012343.JPG

' External SubProgram Library ----------------------------------------------

     $LINK "MODULE.PBL"

' External Functions -------------------------------------------------------

     DECLARE FUNCTION COMPRES$(Strng$,Chars$)
     DECLARE FUNCTION TRANS$  (Strng$,Source$,Target$)

' External Routine ---------------------------------------------------------

     DECLARE SUB PRNTCLR(Text$)

' Start Procedure ----------------------------------------------------------

     DEFINT A-Z  ' All defaulted variables are integer

' Open Data Files ----------------------------------------------------------

     IF (LEN(DIR$("DESCRIPT.ION"))=0) THEN
        CALL PRNTCLR("%R%DSC2REN(1.1)  File %M%DESCRIPT.ION %R%doesn't exist in current dir - %M%program stopped%D%")
        STOP
     END IF

     OPEN "DESCRIPT.ION" FOR  INPUT AS #1
     OPEN "REN-LFN.BAT"  FOR OUTPUT AS #2
     OPEN "REN-8-3.BAT"  FOR OUTPUT AS #3

' Convert DESCRIPT.ION into Rename BAT Files -------------------------------

     WHILE NOT EOF(1)
           LINE INPUT #1,Descr.Line$

'          ----+----1----+----2----+----3----+----4----+---
'          04231927.JPG Tue 04/23/2002 19:27  Park Ave, NYC

           Name.8.3$=LEFT$(Descr.Line$,12)
           DoW$     = MID$(Descr.Line$,14,3)
           Year$    = MID$(Descr.Line$,24,4)
           Month$   = MID$(Descr.Line$,18,2)
           Day$     = MID$(Descr.Line$,21,2)
           Hour$    = MID$(Descr.Line$,29,2)
           Minute$  = MID$(Descr.Line$,32,2)
           Comment$ = MID$(Descr.Line$,36)

           Comment$=TRANS$(COMPRES$(TRANS$(Comment$,".,:;","    ")," ")," ","_")

           Date.Time$=Year$+"-"+Month$+"-"+Day$+"_"+DoW$+"_"+Hour$+"-"+Minute$
           IF (Date.Time$=Prev.Date.Time$) THEN
              Counter=Counter+1
              Modifier$="_"+LTRIM$(STR$(Counter))
           ELSE
              Counter=0
              Modifier$=""
           END IF
           Prev.Date.Time$=Date.Time$
           
           Name.LFN$=Date.Time$+Modifier$+"_"+Comment$+".jpg"
      
           PRINT #2,"REN ";Name.8.3$;" ";Name.LFN$
           PRINT #3,"REN ";Name.LFN$;" ";Name.8.3$
     WEND

' Finish Program -----------------------------------------------------------

     CALL PRNTCLR("%W%Run %G%REN-LFN.BAT %W%in Windows Command session (%Y%not DOS!%W%) to rename image files%D%")

     CLOSE
     END
