Announcement

Collapse
No announcement yet.

scroll statement and qb VIEW

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • scroll statement and qb VIEW

    I've read a few threads here about simulating the old QuickBasic VIEW statement by using SCROLL.

    What I'm trying to do in a console window is to display text like "copying files" at the top, then shell out, run an xcopy, and have the copied files scroll up the screen, but my "copying files" stays at the top.

    I've been messing with SCROLL today, and I must be missing something because I can't really get it do to anything but position text.

    Code:
    ' copy notifier
    
    Function PBMain
        Local fName As String
        Local fNumber As Long         
        Local copyPath As String     
        Local i As Long
        
        ' open the xcopy file    
        ' it should look something like this:
        ' xcopy "\\mmhserv1\Common\Paragon\paragon91217_patches\*.*" "C:\Program Files\Paragon91\*.*" /D
           
        fName="copypath.txt"
        fNumber=FreeFile     
        
        console screen 26, 80
        cls
        If Not exists(fName) Then
            Print "The file copypath.txt is not found."
            Print "This file holds the xcopy statement that executed by batchCopy.exe"
            Print "Please create a copypath.txt file in the same directory as batchCopy.exe"
            Print "Press any key to quit"
            waitkey$
            Exit Function
        End If
                  
        Open fName For Input As #fNumber
        Line Input #fNumber,copyPath
        Close #fNumber    
        
        Color 10,0  
        Print "updating files...."  
        Color 7,0  
        
        SCROLL DOWN 1, 2, 1
                
        Shell(Environ$("COMSPEC") + " /C " + copyPath)            
        
    End Function
    
    
    '---------------------------------------------------------------------------
    ' function name: Exists
    '   description: checks to see if a file exists
    '         input: lostSheep : (variable holding name of file)
    '       returns: true or false
    Function Exists(ByVal LostSheep As String) As Long
      Function = (Len(Dir$(LostSHeep)) > 0)
    End Function

  • #2
    You're not going to be able to simulate the QB View statement. That said,
    You can control where things print and scroll might be an option.

    Probably a better option particularly if you are using only part of the screen,
    is to keep the information that will be displayed in an array and use locate
    statments and keep track of which array item is to be printed first and last.

    Another option might be to use graphic and print the text using the graphic
    statements.
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


    • #3
      Or don't use SHELL. Use CreateProcess or SHellExecuteEx.. both have options to suppress the console or at the very least route STDOUT somewhere it does not step on your existing screen.

      Or just eschew the use of 'xcopy' in favor of handing the copying yourself with PB intrinsic functions, or perhaps using ShFileOperation (which would handle the xcopy statement shown above no problem).


      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        thanks Michael.
        All the files I need to copy are in one folder so it would be fairly easy to get a list and copy them one at a time, and that would allow me to control the display of the files while they copy.

        BTW, I tried to do this in PDS later today and it doesn't work there either, even using PRINT VIEW. If I shell out and run xcopy, it breaks the view window.

        I am going to send this as a wish list item to PB though. My first one.

        Comment


        • #5
          Have you considered running the xcopy in a console window from which you scrape the text (examples in the forums) and post in your control, which you keep TOPMOST during the process?

          Comment


          • #6
            Hi Shawn--

            As far as I know, there isn't any reasonable way to control where XCOPY prints on the console. The only thing you can do is suppress it completely by redirecting the output to a file, or read it with STDIN.

            Personally, I'd just use the PowerBASIC FILECOPY statement instead so you can control it completely.

            Best regards,

            Bob Zale
            PowerBASIC Inc.

            Comment


            • #7
              >the old QuickBasic VIEW ...I tried to do this in PDS later...

              This is not your father's Oldsmobasic.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                FWIW..if you STILL have your heart set on shelling out to something....

                As Mr. Zale points out, you can redirect the stdout and stderr of xcopy (CMD.EXE actually).... and further you can have those outputs sent to YOUR program's stdin* and read it and put it up on the screen whereever you'd like.. and do it all in real time.

                Just off the top of my head, however, getting this to work the way you want it will take you a lot more time than just handling the 'copy' functions yourself in code.

                MCM
                * or you can pipe it. See demo at:
                Anonymous Pipe as Job Queue Demo 10-29-03. A couple of mods and you are in like Flint.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Shawn:

                  The code below was intended to pick a file from the current directory to be processed by the running application. It draw a text "window", preserving the background, and read all the file names in the directory to an array. The width of the "window" is determined by the largest file name, and it is possible to scroll down and up using the cursor keys to select the proper file.

                  By pressing the F7 key the program ask for the folder name and path to which copy all the files in the directory. Using a proper mask it is possible to filter the files to be displayed and/or copied. During the copy process each name is displayed. Closing the "window" by pressing ESC, the background is left unchanged.

                  With some changes and refinements, may be it can be used for your intended purpose.

                  Regards,


                  Code:
                   
                  #COMPILE EXE
                  #DIM ALL
                  #BREAK ON
                   
                  GLOBAL AM%,NO%,L$(),YS%,XS%,SCL?(),LL?(),ARCH$(),TC%(),ATR?(),KA%,AR$,DF$,X%
                   
                  FUNCTION PBMAIN () AS LONG
                   DIM ARCH$(1000)
                   DIM TC%(1000)
                   DIM L$(80),SCL?(50),LL?(50),ATR?(1000)
                   COLOR 7,1
                   CLS
                   LOCATE 24,5:PRINT "Enter - Pick a File   F7 - Copy all to a specified Folder    Esc - Exit"
                   CURSOR OFF
                   ARCH$(1)=DIR$("*.*",6)
                   KA%=1
                   TC%(KA%)=KA%
                   DO
                    AR$=DIR$
                    IF AR$="" THEN
                     EXIT LOOP
                    ELSE
                     INCR KA%
                     ARCH$(KA%)=AR$
                     TC%(KA%)=KA%
                     ATR?(KA%)=GETATTR(AR$)
                     IF AM%<LEN(AR$) THEN AM%=LEN(AR$)
                    END IF
                   LOOP
                   CALL ORD
                   CALL THISONE(AR$,5,3)
                  END FUNCTION
                   
                  SUB ORD
                   LOCAL S%,C%,X%,FLG%
                   S%=KA%
                   FOR C%=1 TO KA%
                    S%=INT(S%/1.3)
                    IF S%<1 THEN S%=1
                    FLG%=0
                    FOR X%=1 TO KA%-S%
                     IF ASC(MID$(ARCH$(TC%(X%)),1,1)) > ASC(MID$(ARCH$(TC%(X%+S%)),1,1)) THEN
                      FLG%=1
                      SWAP TC%(X%),TC%(X%+S%)
                     END IF
                    NEXT X%
                    IF FLG%=0 AND S%=1 THEN EXIT FOR
                   NEXT C%
                  END SUB
                   
                  SUB THISONE(AR$,XS%,YS%)
                   LOCAL IE%,IP%,O$,B%
                   NO%=MIN(15,KA%)
                   CALL WINDOWY(XS%,YS%,AM%,NO%,7,1)
                   IE%=1
                   IP%=0
                   O$=""
                   DO
                    FOR B%=0 TO NO%-1
                     IF B%=IP% THEN
                      COLOR 15,11
                     ELSE
                      COLOR 15,7
                     END IF
                     LOCATE YS%+B%+1,XS%+1
                     PRINT CHR$(32);LEFT$(ARCH$(TC%(B%+IE%))+STRING$(AM%,32),AM%);CHR$(32)
                    NEXT B%
                    DO UNTIL INSTAT
                    LOOP
                    O$=INKEY$
                    IF O$=CHR$(27) THEN
                     AR$=""
                     EXIT LOOP
                    ELSEIF O$=CHR$(0,65) THEN
                     LOCATE 5,40
                     INPUT "Destination folder: ",DF$
                     FOR X%=1 TO KA%
                      LOCATE 10,40
                      COLOR 15,7
                      PRINT LEFT$(ARCH$(X%)+STRING$(AM%,32),AM%)
                      FILECOPY ARCH$(X%), DF$+ARCH$(X%)
                     NEXT
                    ELSEIF O$=CHR$(0,80) THEN
                     IF IP%<NO%-1 THEN
                      INCR IP%
                     ELSE
                      IF IE%<MAX(1,1+KA%-NO%) THEN INCR IE%
                     END IF
                    ELSEIF O$=CHR$(0,72) THEN
                     IF IP%>0 THEN
                      DECR IP%
                     ELSE
                      IF IE%>1 THEN DECR IE%
                     END IF
                    ELSEIF O$=CHR$(0,81) THEN
                     IE%=IE%+NO%
                    ELSEIF O$=CHR$(0,73) THEN
                     IE%=MAX(1,(IE%-NO%))
                    ELSEIF O$=CHR$(13) THEN
                     LOCATE 10,40
                     COLOR 15,7
                     PRINT LEFT$(ARCH$(TC%(IE%+IP%))+STRING$(AM%,32),AM%)
                    END IF
                    IF IE%>1+KA%-NO% THEN IE%=1+KA%-NO%
                    IF IE%<1 THEN IE%=1
                   LOOP
                   CALL WINDOWY(XS%,YS%,AM%,NO%,1,0)
                  END SUB
                   
                   
                  SUB WINDOWY(XS%,YS%,AM%,NO%,CL%,P%)
                   LOCAL F%,V%
                   IF P%=1 THEN
                    FOR F%=YS% TO YS%+NO%+2
                     FOR V%=XS%-1 TO XS%+AM%+2
                      SCL?(F%-YS%,V%-XS%+1)=SCREENATTR(F%,V%)
                      LL?(F%-YS%,V%-XS%+1)=SCREEN(F%,V%)
                     NEXT
                    NEXT
                    COLOR 7,0
                    FOR F%=YS%+1 TO YS%+NO%+1
                     LOCATE F%,XS%-1
                     PRINT SPC(1);
                    NEXT
                    LOCATE YS%+NO%+2,XS%-1
                    PRINT SPC(AM%+4)
                    COLOR 15,CL%
                    LOCATE YS%,XS%:PRINT CHR$(218);STRING$(AM%+2,196);CHR$(191);
                    LOCATE YS%+NO%+1,XS%:PRINT CHR$(192);STRING$(AM%+2,196);CHR$(217);
                    FOR F%=1 TO NO%
                     LOCATE YS%+F%,XS%:PRINT CHR$(179)+STRING$(AM%+2,32)+CHR$(179);
                    NEXT
                   ELSE
                    FOR F%=YS% TO YS%+NO%+2
                     FOR V%=XS%-1 TO XS%+AM%+2
                      LOCATE F%,V%
                      COLOR (SCL?(F%-YS%,V%-XS%+1) MOD 16),(SCL?(F%-YS%,V%-XS%+1)\16)
                      PRINT CHR$(LL?(F%-YS%,V%-XS%+1));
                     NEXT
                    NEXT
                   END IF
                  END SUB
                  Last edited by Manuel Valdes; 5 Oct 2009, 09:33 AM.

                  Comment


                  • #10
                    Adding some improvements and functions, the code ended as a working applet. Note the inclusion of a function posted by Michael Mattias as Public Domain, to get formatted the File Dates and Times.

                    Best regards,

                    Code:
                     
                    #COMPILE EXE
                    #DIM ALL
                    #BREAK ON
                     
                    TYPE FILETIME
                     dwLowDateTime AS DWORD
                     dwHighDateTime AS DWORD
                    END TYPE
                     
                    TYPE SYSTEMTIME
                     wYear AS WORD
                     wMonth AS WORD
                     wDayOfWeek AS WORD
                     wDay AS WORD
                     wHour AS WORD
                     wMinute AS WORD
                     wSecond AS WORD
                     wMilliseconds AS WORD
                    END TYPE
                     
                    DECLARE FUNCTION FileTimeToLocalFileTime LIB "KERNEL32.DLL" ALIAS "FileTimeToLocalFileTime" (lpFileTime AS FILETIME, lpLocalFileTime AS FILETIME) AS LONG
                    DECLARE FUNCTION FileTimeToSystemTime LIB "KERNEL32.DLL" ALIAS "FileTimeToSystemTime" (lpFileTime AS FILETIME, lpSystemTime AS SYSTEMTIME) AS LONG
                    DECLARE FUNCTION GetDateFormat LIB "KERNEL32.DLL" ALIAS "GetDateFormatA" (BYVAL Locale AS LONG, BYVAL dwFlags AS DWORD, lpDate AS SYSTEMTIME, lpFormat AS ASCIIZ, lpDateStr AS ASCIIZ, BYVAL cchDate AS LONG) AS LONG
                    DECLARE FUNCTION GetTimeFormat LIB "KERNEL32.DLL" ALIAS "GetTimeFormatA" (BYVAL Locale AS LONG, BYVAL dwFlags AS DWORD, lpTime AS SYSTEMTIME, lpFormat AS ASCIIZ, lpTimeStr AS ASCIIZ, BYVAL cchTime AS LONG) AS LONG
                     
                    GLOBAL AM%,NO%,L$(),YS%,XS%,PTH$,ARCH$(),TC%(),ATR?(),KA%,AR$,DF$,X%,TG?()
                    GLOBAL DD AS DirData
                     
                    FUNCTION PBMAIN () AS LONG
                     DIM ARCH$(1000),TC%(1000),TG?(1000)
                     DIM ATR?(1000)
                     COLOR 7,1
                     CLS
                     PRINT "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿";
                     PRINT "³ Copy from:                                                                   ³";
                     PRINT "³                                                                              ³";
                     PRINT "³ Copy to  :                                                                   ³";
                     PRINT "ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´";
                     PRINT "³             Files                Tagged ³            File Data               ³";
                     PRINT "ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "³                                         ³                                    ³";
                     PRINT "ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´";
                     PRINT "³                                                                              ³";
                     PRINT "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ";
                     LOCATE 24,3:PRINT "Enter-FileData Ins-Tag/Untag F5-Tag_All F6-Untag_All F7-Copy_Tagged Esc-Exit
                     COLOR 14,1
                     LOCATE 24,3:PRINT "Enter"
                     LOCATE 24,18:PRINT "Ins"
                     LOCATE 24,32:PRINT "F5"
                     LOCATE 24,43:PRINT "F6"
                     LOCATE 24,56:PRINT "F7"
                     LOCATE 24,71:PRINT "Esc"
                     LOCATE 2,14:INPUT "",PTH$
                     IF PTH$="" THEN PTH$=CURDIR$
                     LOCATE 2,14:PRINT LEFT$(PTH$,66)
                     CURSOR OFF
                     ARCH$(1)=DIR$(PTH$+"\*.*")
                     KA%=1
                     TC%(KA%)=KA%
                     TG?(KA%)=32
                     DO
                      AR$=DIR$
                      IF AR$="" THEN
                       EXIT LOOP
                      ELSE
                       INCR KA%
                       ARCH$(KA%)=AR$
                       TC%(KA%)=KA%
                       ATR?(KA%)=GETATTR(AR$)
                       TG?(KA%)=32
                       IF AM%<LEN(AR$) THEN AM%=LEN(AR$)
                      END IF
                     LOOP
                     am%=MIN(am%,32)
                     LOCATE 6,10:PRINT USING$("####",KA%)
                     CALL ORD
                     CALL THISONE(AR$,1,7)
                    END FUNCTION
                     
                    SUB ORD
                     LOCAL S%,C%,X%,FLG%
                     S%=KA%
                     FOR C%=1 TO KA%
                      S%=INT(S%/1.3)
                      IF S%<1 THEN S%=1
                      FLG%=0
                      FOR X%=1 TO KA%-S%
                       IF ASC(MID$(ARCH$(TC%(X%)),1,1)) > ASC(MID$(ARCH$(TC%(X%+S%)),1,1)) THEN
                        FLG%=1
                        SWAP TC%(X%),TC%(X%+S%)
                       END IF
                      NEXT X%
                      IF FLG%=0 AND S%=1 THEN EXIT FOR
                     NEXT C%
                    END SUB
                     
                    SUB THISONE(AR$,XS%,YS%)
                     LOCAL IE%,IP%,O$,B%,TT%
                     NO%=MIN(15,KA%)
                     IE%=1
                     IP%=0
                     O$=""
                     DO
                      FOR B%=0 TO NO%-1
                       IF B%=IP% THEN
                        COLOR 15,11
                       ELSE
                        COLOR 15,1
                       END IF
                       LOCATE YS%+B%+1,XS%+1
                       PRINT CHR$(32);LEFT$(ARCH$(TC%(B%+IE%))+STRING$(37,32),37);CHR$(32);CHR$(TG?(TC%(B%+IE%)));CHR$(32)
                      NEXT B%
                      DO UNTIL INSTAT
                      LOOP
                      O$=INKEY$
                      IF O$=CHR$(27) THEN
                       AR$=""
                       EXIT LOOP
                      ELSEIF O$=CHR$(0,82) THEN   'Insert
                       IF TG?(TC%(IP%+IE%))= 32 THEN
                        TG?(TC%(IP%+IE%))=43
                       ELSE
                        TG?(TC%(IP%+IE%))= 32
                       END IF
                      ELSEIF O$=CHR$(0,63) THEN  'F5
                       FOR X%=1 TO KA%
                        TG?(x%)=43
                       NEXT
                      ELSEIF O$=CHR$(0,64) THEN  'F6
                       FOR X%=1 TO KA%
                        TG?(x%)=32
                       NEXT
                      ELSEIF O$=CHR$(0,65) THEN  'F7
                       LOCATE 4,14
                       COLOR 14,1
                       INPUT "",DF$
                       IF DF$<>"" THEN
                        FOR X%=1 TO KA%
                         CALL DET(X%,0)
                         IF TG?(X%)=43 THEN FILECOPY ARCH$(X%), DF$+ARCH$(X%)
                        NEXT
                       END IF
                       WAITKEY$
                       LOCATE 4,14
                       PRINT SPC(66)
                      ELSEIF O$=CHR$(0,80) THEN  'Arrow Down
                       IF IP%<NO%-1 THEN
                        INCR IP%
                       ELSE
                        IF IE%<MAX(1,1+KA%-NO%) THEN INCR IE%
                       END IF
                      ELSEIF O$=CHR$(0,72) THEN   'Arrow Up
                       IF IP%>0 THEN
                        DECR IP%
                       ELSE
                        IF IE%>1 THEN DECR IE%
                       END IF
                      ELSEIF O$=CHR$(0,81) THEN   'Pg Down
                       IE%=IE%+NO%
                      ELSEIF O$=CHR$(0,73) THEN   'Pg Up
                       IE%=MAX(1,(IE%-NO%))
                      ELSEIF O$=CHR$(13) THEN     'Enter
                       CALL DET(IE%,IP%)
                      END IF
                      IF IE%>1+KA%-NO% THEN IE%=1+KA%-NO%
                      IF IE%<1 THEN IE%=1
                      TT%=0
                      FOR X%=1 TO KA%
                       IF TG?(X%)=43 THEN INCR TT%
                      NEXT
                      COLOR 14,1
                      LOCATE 6,31:PRINT USING$("####",TT%)
                     LOOP
                    END SUB
                     
                    'Get Formatted date and time info from DIRDATA structure
                    'Author: Michael Mattias, Racine WI  3/10/09
                    'USE: Placed in public domain
                    SUB GetformattedDirDataDateTime (DTOI AS QUAD, sDate AS STRING, sTime AS STRING)
                     LOCAL szDate AS ASCIIZ * 48, szTime AS ASCIIZ * 48
                     LOCAL szDF   AS ASCIIZ * 48, szTF AS ASCIIZ * 48
                     LOCAL ft AS FILETIME
                     LOCAL ST AS SYSTEMTIME
                     LOCAL lft AS FILETIME
                     LOCAL pFT AS FILETIME PTR
                     IF DTOI <> 0 THEN
                      pFT = VARPTR(DTOI)
                      FileTimeToLocalFileTime @pFT, lft
                      FileTimeToSystemTime lft, St
                      szDF = "MM'-'dd'-'yyyy"
                      GetDateFormat BYVAL 0, BYVAL 0,st, szDf, szDate, SIZEOF (szDate)
                      szTF = "HH':'mm':'ss"
                      GettimeFormat BYVAL 0, BYVAL 0,st, szTF, szTime, SIZEOF (szTime)
                      ELSE
                       szDate  = "N/A"
                       szTime  = "N/A"
                      END IF
                      sDate = szDate
                      sTime = szTime
                    END SUB
                     
                    SUB DET(IE%,IP%)
                     LOCAL fDate AS STRING, fTime AS STRING
                     LOCATE 8,45
                     COLOR 15,1
                     PRINT LEFT$(ARCH$(TC%(IE%+IP%))+STRING$(AM%,32),AM%)
                     AR$=DIR$(PTH$+"\"+ARCH$(TC%(IE%+IP%)), TO DD)
                     LOCATE 11,45
                     PRINT "Attributes  : ";DD.FileAttributes
                     LOCATE 13,45
                     CALL GetFormattedDirdataDateTime (DD.CreationTime, fDate, fTime)
                     PRINT "Created     : ";fdate;CHR$(32,32);ftime
                     LOCATE 15,45
                     CALL GetFormattedDirdataDateTime (DD.LastAccessTime, fDate, fTime)
                     PRINT "Last Access : ";fDate;CHR$(32,32);fTime
                     LOCATE 17,45
                     CALL GetFormattedDirdataDateTime (DD.LastWriteTime, fDate, fTime)
                     PRINT "Last Write  : ";fDate;CHR$(32,32);fTime
                     LOCATE 19,45
                     PRINT "File Size   : ";USING$("###,###,###",DD.FileSizeLow)
                     LOCATE 21,45
                     PRINT "Short Name  : ";DD.ShortName
                    END SUB

                    Comment


                    • #11
                      First of all, thanks to everyone for their input. There are a lot of great ideas to glean for this and later projects.
                      Anyway, since all the files being copied are in the same folder, this is what I ended up with:

                      Code:
                      ' copy notifier
                      
                      #Include "win32api.inc"
                      
                      Type DirData
                        FileAttributes        As Dword
                        CreationTime          As Quad
                        LastAccessTime        As Quad
                        LastWriteTime         As Quad
                        FileSizeHigh          As Dword
                        FileSizeLow           As Dword
                        Reserved0             As Dword
                        Reserved1             As Dword
                        FileName              As Asciiz * 260
                        ShortName             As Asciiz * 14
                      End Type
                      
                      
                      Function PBMain
                          Local fName As String
                          Local fNumber As Long         
                          Local fSpec As String      
                          Local iYear,iHour,iMonth,iMinute,iDay,iSecond As Long   
                          Local fromDir As String
                          Local toDir As String           
                          Dim listing(1) As dirData      
                          Local i As Long         
                          Local lineNumber As Long            
                          Local toFile As String        
                          Local cTime As Quad     
                          Local fromFile As String
                          
                          ' open the xcopy file                
                          ' line one is source folder
                          ' line to is destination folder
                          ' it should look something like this:
                          ' \\mmhserv1\Common\Paragon\paragon91217_patches\
                          ' C:\Program Files\Paragon91\
                             
                          fName="copypath.txt"
                          fNumber=FreeFile           
                          
                          cls
                          If Not fileExists(fName) Then
                              Print "The file copypath.txt is not found."
                              Print "This file holds the xcopy statement that executed by batchCopy.exe"
                              Print "Please create a copypath.txt file in the same directory as batchCopy.exe"
                              Print "Press any key to quit"
                              waitkey$
                              Exit Function
                          End If
                                    
                          Open fName For Input As #fNumber      
                          Line Input #fNumber,fromDir
                          Line Input #fNumber,toDir
                          Close #fNumber   
                          
                          ' always end with a slash
                          If Right$(fromDir,1)<> "\" Then fromDir+="\"                     
                          If Right$(toDir,1)<> "\" Then toDir+="\"                     
                          
                          ' make sure directories are good
                          If Not dirExists(fromDir) Then
                              Print "missing or invalid 'from' directory in copypath.txt... quitting in 5 seconds"
                              Sleep 5000
                              Exit Function
                          End If  
                          
                          If Not dirExists(toDir) Then
                              Print "missing or invalid 'to' directory in copypath.txt... quitting in 5 seconds"
                              Exit Function
                          End If   
                                                      
                          Color 10,0    
                          locate 1,1
                          Print "updating files...."           
                          Color 7,0     
                          
                          ' get a list of files to an array    
                          lineNumber=2
                          fileList(fromDir,listing())      
                          
                          For i = 0 To UBound(listing())            
                              If listing(i).creationTime=0 Then Exit For
                              
                              Incr lineNumber
                              locate lineNumber,1
                              
                              fromFile=fromDir+listing(i).fileName    
                              ' I'm not sure why but the source file has a *.* in it??
                              ' dir$ must do that
                              Replace "*.*" With "" In fromFile
                              toFile=toDir+listing(i).fileName
                              
                              Color 3,0
                              If fileExists(toFile) Then              
                                  ' compare dates
                                  If getFileCreationTime(toFile) < listing(i).creationTime Then
                                     ' toFile is older so copy new file
                                     Color 7,0   
                                     Print "copying "+fromFile+" to "+toFile   
                                  
                                  Else                    
                                     ' destination file is newer or same so just print
                                     Print "not copying "+listing(i).fileName';" ";Format$(listing(i).creationTime,"0")  
                                  End If
                              Else    
                                  ' file doesn't exist at destination so copy it     
                                  Color 7,0
                                  Print "copying "+fromFile+" to "+toFile   
                                  FileCopy fromFile, toFile
                              End If
                              
                              If LineNumber>20 Then                
                                  clearStuff()
                                  lineNumber=2
                              End If
                              
                          Next    
                          Color 10,0
                          Print "" 
                          Print "done... closing in 2 seconds"
                          Color 7,0
                          Sleep 2000
                              
                          
                      End Function     
                      
                      '---------------------------------------------------------------------------
                      ' function name: clearStuff
                      '   description: sorry, I wasn't very inventive with the name
                      '                clears the bottom of the screen
                      '         input: nothing
                      '       returns: nothing (clear screen)
                      Function clearStuff() As Long
                          Local i As Long
                          For i = 3 To 22     
                              Locate i,1    
                              Print Space$(80)  
                          Next   
                      End Function       
                      
                      '---------------------------------------------------------------------------
                      ' function name: getFileCreationTime
                      '   description: returns file creation time for file toFile
                      '         input: complete path+fileName
                      '       returns: values for creationg time
                      Function getFileCreationTime(toFile As String) As Quad     
                          Dim listing As dirData     
                          Local a As String 
                          a=Dir$(toFile, To listing )
                          Function=listing.creationTime
                      End Function
                      
                      
                      '---------------------------------------------------------------------------
                      ' function name: fileExists
                      '   description: checks to see if a file exists
                      '         input: fName : (variable holding name of file)
                      '       returns: true or false
                      Function fileExists(ByVal fName As String) As Long
                        Function = (Len(Dir$(fName)) > 0)
                      End Function                     
                      
                      '---------------------------------------------------------------------------
                      ' function name: dirExists
                      '   description: checks to see if a directory exists
                      '         input: DirPath: directory name
                      '       returns: true or false
                      Function DirExists(DirPath As String) As Long
                        Function = (Dir$(RTrim$(DirPath,"\"), %SUBDIR) <> "")
                      End Function
                      
                      
                      '---------------------------------------------------------------------------
                      ' function name: fileList
                      '   description: returns a list of files in a directory with attributes
                      '         input: fromDir: directory to parse
                      '       returns: values for year,month,day,hour,minute,second
                      Function fileList(fromDir As String,listing() As DirData) As Long
                          ReDim Listing(2000) As DirData
                          Local x As Long
                          Local temp As String
                          
                          ' add backslash if it isn't there
                          If Right$(fromDir,1)<>"\" Then fromDir=fromDir+"\"      
                          
                          fromDir=fromDir+"*.*"
                      
                          temp = Dir$(fromDir, To Listing(x))   
                          
                          x=0
                          Do While Len(temp) And x < 2000 ' max = 2000 files       
                            Incr x
                            temp = Dir$(Next, To Listing(x) )      
                          Loop        
                      
                      End Function

                      Comment


                      • #12
                        ???
                        Code:
                        Function getFileCreationTime(toFile As String) As Quad     
                            Dim listing As dirData     
                            Local a As String 
                            a=Dir$(toFile, To listing )
                        [COLOR="Red"]    IF LEN(A) THEN [/COLOR] 
                                   Function=listing.creationTime
                        [COLOR="Red"]    ELSE
                                   Function =  some value meaning 'not found' 
                            END IF [/COLOR]
                        End Function
                        ???
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          yes, thanks

                          Comment


                          • #14
                            That's always something I wonder about....

                            Should I check for existence BEFORE I ask for something?

                            Or do I check for existence WHILE getting what I was asked for?

                            In this case, is it a 'condition' of the getFileCreationTime() function the target file exists? Or should that function check and return "some value" indicating the target file was not found?

                            In real life what usually happens is I end up checking twice.

                            MCM
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              In this particular case, creationTime already returns 0 if the file does not exist. It's probably better to, as you suggest, explicitly determine if the file exists.

                              Comment


                              • #16
                                The PB compilers do a nice job of initializing variables, but for a long time I did a lot of COBOL work, and if you don't initialize things yourself you get pot luck.

                                e.g. in this case, using COBOL 'creationtime' might NOT come back as zero when the file does not exist.
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  pb does spoil me

                                  Comment

                                  Working...
                                  X