Dir.Copy Progress Status Output

Questions regarding syntax

Dir.Copy Progress Status Output

Postby DevConcepts » Mon Oct 04, 2010 2:03 pm

I was wondering if there is a way to get the copying progress of Dir.Copy to feed a progress bar?

The other option would seem to be to do a recursive file list, create directories and then monitor the file copy progress based off of the list.

Any Ideas?
DevConcepts
 
Posts: 10
Joined: Sat Feb 21, 2009 5:17 pm

Re: Dir.Copy Progress Status Output

Postby Slowdown » Mon Oct 04, 2010 6:34 pm

I was wondering if there is a way to get the copying progress of Dir.Copy to feed a progress bar?

nope, it's a function and the only way to change it is diving into the source of KBasic :o
The other option would seem to be to do a recursive file list, create directories and then monitor the file copy progress based off of the list.

This would work, the only drawback if you have large directory's you do have a progressbar wich keeps the same
for a longer time period.
If you want to follow the copy progress you have to monitor on file level.
If you use file.copy you encounter the same problem as Dir.copy.
If you want to monitor on file level see the examples 'filecopy.kbasic' project.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Dir.Copy Progress Status Output

Postby DevConcepts » Mon Oct 04, 2010 10:58 pm

Slowdown wrote:This would work, the only drawback if you have large directory's you do have a progressbar wich keeps the same
for a longer time period.
If you want to follow the copy progress you have to monitor on file level.
If you use file.copy you encounter the same problem as Dir.copy.
If you want to monitor on file level see the examples 'filecopy.kbasic' project.


What I meant was using the progress bar to monitor the list of files (Say 2000 files) as the files are copied one by one (500 of 2000 copied = 25% bar). It would not be a byte counter. Still a pain.
DevConcepts
 
Posts: 10
Joined: Sat Feb 21, 2009 5:17 pm

Re: Dir.Copy Progress Status Output

Postby berndnoetscher » Tue Oct 05, 2010 10:02 am

DevConcepts wrote:
Slowdown wrote:This would work, the only drawback if you have large directory's you do have a progressbar wich keeps the same
for a longer time period.
If you want to follow the copy progress you have to monitor on file level.
If you use file.copy you encounter the same problem as Dir.copy.
If you want to monitor on file level see the examples 'filecopy.kbasic' project.


What I meant was using the progress bar to monitor the list of files (Say 2000 files) as the files are copied one by one (500 of 2000 copied = 25% bar). It would not be a byte counter. Still a pain.


Never did it before, so there is no example, but the dir example shows how to get a list of directories, which could be copied.
As an idea how to implement a progress dialog.

http://www.kbasic.com/doku.php?id=stati ... ressdialog
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Dir.Copy Progress Status Output

Postby Slowdown » Tue Oct 05, 2010 7:25 pm

Hi DevConcepts,

an idea,
Code: Select all
Private Sub SelectDir_OnEvent()
  Dim GetDirs As String = OpenDialog.GetDirectory()
  Dim FileCount As Integer, Counter As Integer
  Dim CurrentFile As String
 
  If GetDirs Then
    Dim AllMyFiles As Strings = Dir.FindFile(GetDirs & "/", "*", "Files;System;Hidden")
    FileCount = AllMyFiles.length   ' Total number of files found.
   
    For Counter = 1 To FileCount
      CurrentFile = AllMyFiles.String(Counter)
      Log File.name(CurrentFile)
      ' put here your copy file function / Sub
      ' You have the total number of files and
      ' number of the file copied tada .....
    Next
  End If
End Sub

Private Sub SelectDir_OnEvent() is a Button
Sorry don't have the time at this moment to work it out in more details.
If you need more just let me know but be patient.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Dir.Copy Progress Status Output

Postby berndnoetscher » Fri Oct 08, 2010 10:06 am

Thanks to slowdown. Has created an example how to do it. Here is the source code. I will add it to the next kbasic release.
Thanks :-)

Code: Select all
/*
  October 6 2010
  Example copy files from directory to directory and use a progressbar
  for monitoring results.
  Written in KBasic 1.89(u) under OSX Snow Leopard
  you can reach me on the KBasic forum http://www.kbasic.com/forum/index.php user Slowdown
 
*/


Public SourceDir As String
Public DestinationDir As String

Private Sub SelectDir_OnEvent()
  SourceDir = OpenDialog.GetDirectory()
  Label1.Caption = "From: " & SourceDir
End Sub

Private Sub DestDirectory_OnEvent()
  DestinationDir = OpenDialog.GetDirectory()
  Label2.Caption = "To: " & DestinationDir
End Sub

Private Sub StartCopy_OnEvent()
  Dim Counter As Integer, TotalFiles As Integer
  Dim CurrentFile As String
 
  If SourceDir = "" Then
    MsgBox("No source directory selected", kbOKOnly, "User information")
    Exit Sub
  End If 
  If DestinationDir = "" Then
    MsgBox("No destination directory selected", kbOKOnly, "User information")
    Exit Sub
  End If 

  If SourceDir Then
    Dim AllMyFiles As Strings = Dir.FindFile(SourceDir & "/", "*", "Files;System;Hidden")
    TotalFiles = AllMyFiles.length   ' Total number of files found.
    ProgressBar1.maximum = TotalFiles

    For Counter = 1 To TotalFiles
      CurrentFile = File.Name(AllMyFiles.String(Counter))
      ProgressBar1.Value = Counter
      File.Copy(SourceDir & "/" & CurrentFile, DestinationDir & "/" & CurrentFile)
      DoEvents
    Next
    MsgBox("Number of Files copied " & Str(TotalFiles))
  End If
End Sub




berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Dir.Copy Progress Status Output

Postby DevConcepts » Sun Oct 10, 2010 2:28 am

OOPS!! Found a problem with the code. It only copies files in the source root folder and skips all sub dir's and files.

The code below is not commented (Yet) and has an issue of using a listbox as I couldn't get the array (Or Strings) to work. It will also not copy empty directories, but I think if there empty, why copy.

Code: Select all
Public SourceDir As String
Public DestinationDir As String

Private Sub SelectDir_OnEvent()
    SourceDir = OpenDialog.GetDirectory()
  Label1.Caption = "From: " & SourceDir
End Sub



Private Sub DestDirectory_OnEvent()
    DestinationDir = OpenDialog.GetDirectory()
  Label2.Caption = "To: " & DestinationDir
End Sub

Private Sub StartCopy_OnEvent()
  Dim Counter As Integer
  Dim Counter2 As integer
  Dim TotalFiles As Integer
  dim DirMarker As Integer
  Dim CurrentFile As String
  Dim CurrentFileDest As String
  Dim TempPath As String
 
  If SourceDir = "" Then
    MsgBox("No source directory selected", kbOKOnly, "User information")
    Exit Sub
  End If 
  If DestinationDir = "" Then
    MsgBox("No destination directory selected", kbOKOnly, "User information")
    Exit Sub
  End If 

  If SourceDir Then
    Dim AllMyFiles As Strings = Dir.RecursiveFileList(SourceDir)
    Dim AllMyDirs as Strings
    Dim iLastDir as Integer
    Dim iSPL As integer
    Dim iFPL as integer
    Dim DirChar as String
    Dim ChkPath as String
    Dim ChkPE as integer
    TotalFiles = AllMyFiles.length
    ProgressBar1.maximum = TotalFiles
        For Counter = 1 to TotalFiles'Subtract Prior Source Path
          iSPL = Len (SourceDir)
          iFPL = Len((AllMyFiles.String(Counter)))
          TempPath = Mid(AllMyFiles.String(Counter), iSPL+2, (iFPL-iSPL)-1)
          For DirMarker = Len (TempPath) to 1 Step -1
              DirChar = Mid(TempPath,DirMarker,1)
              If DirChar = "/" then
                TempPath = Mid(TempPath,1,DirMarker-1)
                 For Counter2 = 1 to Listbox1.length
                   Listbox1.select(Counter2)
                   ChkPath = Listbox1.Caption
                   If ChkPath = TempPath then
                     ChkPE=1
                     Exit For
                   End If
                  Next
                  If ChkPE=0 then
                    ListBox1.Append (TempPath)
                  Elseif ChkPE=1 then
                    ChkPE=0
                  End If
                Exit For
             End If
            DoEvents
            Next
        Next

        For Counter = 1 to ListBox1.Length
          Dim Dirs as String
          ListBox1.Select(Counter)
          Dirs = Listbox1.Caption
        Dir.RecursiveCreate (DestinationDir & "/" & Dirs)
        Next
       
        For Counter = 1 To TotalFiles
          iSPL = Len (SourceDir)
          iFPL = Len((AllMyFiles.String(Counter)))
          TempPath = Mid(AllMyFiles.String(Counter), iSPL+2, (iFPL-iSPL)-1)
        CurrentFileDest = DestinationDir & "/" & TempPath
        ProgressBar1.Value = Counter
        File.Copy((AllMyFiles.String(Counter)), CurrentFileDest)
        DoEvents
       Next
        MsgBox("Number of Files copied " & Str(TotalFiles))
  End If
End Sub
DevConcepts
 
Posts: 10
Joined: Sat Feb 21, 2009 5:17 pm

Re: Dir.Copy Progress Status Output

Postby Slowdown » Sun Oct 10, 2010 8:05 am

OOPS!! Found a problem with the code. It only copies files in the source root folder and skips all sub dir's and files.

Not a problem, didn't wrote recursive code in the example ;)
If i have some time i'll look into your code.
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Dir.Copy Progress Status Output

Postby DevConcepts » Sun Oct 10, 2010 4:45 pm

Slowdown wrote:Not a problem, didn't wrote recursive code in the example ;)
If i have some time i'll look into your code.


Sorry, I thought it was complete for recursive.
DevConcepts
 
Posts: 10
Joined: Sat Feb 21, 2009 5:17 pm


Return to Coding Questions

cron