Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

DIR2COP  PowerBASIC  Procedure

         

DIR2COP procedure (external program executable from the DOS command prompt) converts alphabetical list of files into batch script (mainly COPY commands).  The result of conversion is C:\ORDERDIR.BAT file that could be run in Windows Command session (not DOS!) to ensure the actual alphabetical order of files within specified directory.  One obvious use of this (for which this program was developed) is to order directory of sound files by file name prefixes bypassing the need for the palylists that on most part are not supported by portable MP3 players.

Direct dependencies:

REVERSE$ Reverse character string
TAILSTR$ Get character string tail



 DIR2COP  Source  Program                                                                   Debugging example

      ' DIR2COP(1.1)  Convert Directory into COPY Batch Scr  11/07/2005-12/15/2005
      ' --------------------------------------------------------------------------
      ' Copyright (C) 2005 by Vladimir Veytsel                       www.davar.net

      ' Type ---------------------------------------------------------------------

      '    Procedure

      ' Parameter ----------------------------------------------------------------

      '    1. Full path to the directory to be ordered.

      ' Necessity ----------------------------------------------------------------

      '    The need for this procedure arises from the typical situation when
      '    files get placed into directory in the random order, while processing
      '    is required in alphabetical order.  One example is song or narration
      '    directory that gets ordered by numeric prefixes to the file names to
      '    avoid dealing with playlists, which require some effort to maintain,
      '    and that might be not supported by portable MP3 player.

      ' Approach -----------------------------------------------------------------

      '  - Three files were copied in the newly created directory "Test".
      '    Files were intentionally copied in the REVERSE alphabetical order.

      '    DIR command shows file names in the alphabetical order.

      '    C:\> DIR /B E:\Manual\PDF\Test

      '    Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
      '    Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '    Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf

      '    TREE command shows the ACTUAL file order - REVERSE alphabetical.

      '    C:\> TREE /A /F E:\Manual\PDF\Test

      '    E:\Manual\PDF\Test
      '    +--Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf
      '    +--Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '    \--Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf

      '  - This batch script was used to order directory "Test" alphabetically.

      '    C:\> TYPE C:\ORDERDIR.BAT

      '    MD E:\Manual\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf E:\Manu
      '    al\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf E:\Manu
      '    al\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf E:\Manu
      '    al\PDF\ORDERDIR
      '    DEL /Y E:\Manual\PDF\Test\*.*
      '    RD E:\Manual\PDF\Test
      '    REN E:\Manual\PDF\ORDERDIR E:\Manual\PDF\Test

      '  - Batch script execution.

      '    C:\> C:\ORDERDIR.BAT

      '    E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf => E:\Manual
      '    \PDF\ORDERDIR\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
      '         1 file copied
      '    E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf => E:\Manual
      '    \PDF\ORDERDIR\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '         1 file copied
      '    E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf => E:\Manual
      '    \PDF\ORDERDIR\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf
      '         1 file copied
      '    Deleting E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf
      '    Deleting E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '    Deleting E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
      '         3 files deleted       1,445,888 bytes freed
      '    E:\Manual\PDF\ORDERDIR -> E:\Manual\PDF\Test
      '         1 file renamed

      '  - TREE command shows the ACTUAL file order - ALPHABETICAL
      '    (result of directory reordering).

      '    C:\> TREE /A /F E:\Manual\PDF\Test

      '    E:\Manual\PDF\Test
      '    +--Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
      '    +--Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '    \--Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf

      ' Example ------------------------------------------------------------------

      '  - E:\Manual\PDF\Test  - Parameter:  FULL path to directory to be ordered

      '  - List of directory files is expected to be found in C:\ORDERDIR.LST
      '    (created by "DIR /B E:\Manual\PDF\Test > C:\ORDERDIR.LST" command)

      '    Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
      '    Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
      '    Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf

      '  - Program DIR2COP generates C:\ORDERDIR.BAT based on the path specified
      '    by program parameter, and the alphabetical list of directory files.

      '    MD E:\Manual\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf E:\Manual\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf E:\Manual\PDF\ORDERDIR
      '    COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf E:\Manual\PDF\ORDERDIR
      '    DEL /Y E:\Manual\PDF\Test\*.*
      '    RD E:\Manual\PDF\Test
      '    REN E:\Manual\PDF\ORDERDIR E:\Manual\PDF\Test

      ' Notes --------------------------------------------------------------------

      '  - An important presumption for described functionality is that the drive
      '    specified in the path has enough space to duplicate all directory files.

      '  - Program is designed to work from within batch script, so any validations
      '    are omitted.

      ' External SubProgram Library ----------------------------------------------

           $LINK "MODULE.PBL"

      ' External Functions -------------------------------------------------------

           DECLARE FUNCTION REVERSE$(Strng$)
           DECLARE FUNCTION TAILSTR$(Strng$,Delim$)

      ' Start Procedure ----------------------------------------------------------

           DEFINT A-Z  ' All defaulted variables are integer

      ' Get Control Parameter ----------------------------------------------------

           Parm$=COMMAND$
      '    Parm$="E:\Manual\PDF\Test"

      ' Open Data Files ----------------------------------------------------------

           OPEN "C:\ORDERDIR.LST" FOR  INPUT AS #1
           OPEN "C:\ORDERDIR.BAT" FOR OUTPUT AS #2

      ' Convert ORDERDIR.LST into ORDERDIR.BAT File ------------------------------

           File.Path$=REVERSE$(TAILSTR$(REVERSE$(Parm$),"\"))
           PRINT #2,"MD ";File.Path$;"\ORDERDIR"

           WHILE NOT EOF(1)
                 LINE INPUT #1,File.Name$
                 PRINT #2,"COPY ";Parm$;"\";File.Name$;" ";File.Path$;"\ORDERDIR"
           WEND

           PRINT #2,"DEL /Y ";Parm$;"\*.*"
           PRINT #2,"RD ";Parm$
           PRINT #2,"REN ";File.Path$;"\ORDERDIR";" ";Parm$

      ' Finish Program -----------------------------------------------------------

           CLOSE
           END
  
         

 DIR2COP  Debugging  Example                                                                Source program
         

Below there is a list of E:\Manual\PDF\Test directory files, and result of DIR2COP program execution
C:\ORDERDIR.BAT batch script file that will order E:\Manual\PDF\Test directory when executed.

         

   FILE:  C:\ORDERDIR.LST
   -------------------------------------------------
   Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf
   Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf
   Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf
        
      
         

   FILE:  C:\ORDERDIR.BAT
   ------------------------------------------------------------------------------------------------  
   MD E:\Manual\PDF\ORDERDIR
   COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_51_1999)_amqdac0x.pdf E:\Manual\PDF\ORDERDIR
   COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_52_2001)_amqdac03.pdf E:\Manual\PDF\ORDERDIR
   COPY E:\Manual\PDF\Test\Solaris_Beginnings_(IBM_MQS_53_2002)_amqdac05.pdf E:\Manual\PDF\ORDERDIR
   DEL /Y E:\Manual\PDF\Test\*.*
   RD E:\Manual\PDF\Test
   REN E:\Manual\PDF\ORDERDIR E:\Manual\PDF\Test
        
      

         

View [and save] DIR2COP.BAS text       Download DIR2COP.EXE file
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 2005 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top