Page 1 of 1

Copy files using progress bar

Posted: Tue Nov 25, 2008 8:54 am
by alemrantareq
Hi everybody,

I've a button and a progress bar. I wanna use the progress bar for copying some files after clicking that btn. What will be the script for btn as well as the progress bar to do that? Pls help me...

Posted: Fri Nov 28, 2008 12:40 am
by Mark
Hi alemrantareq,

What have you tried so far? I assume you already have a script that reads the file and writes it in a different location. If you indeed have such a script, you can modify it by adding a repeat loop, to start with. Once you have figured out how to do that, it is not a very big step to adding a progress bar.

I propose you post your script here and then we can see how to help you.

Best regards,

Mark

Posted: Sun Nov 30, 2008 8:59 am
by alemrantareq
Hi mark,
Thanks for your reply. I've three files which I can copy using "revcopyfile" command. As a progress bar is a scroll bar and that shows how many times a task take to complete, I've made a deep search on repeat loop. But I'm wondering how to show a progressbar at the time of copying those files as I've not enough knowledge about repeat loop. I think it can be done like this "repeat with n = 1 to 100", where n is the counter but not sure how to make script with it. I've a progressbar named "progress" which starttime is 1 and endtime is 100 and a btn to copy those files. Now I'm trying to learn what will be the btn script as well as the progressbar script.

Posted: Sun Nov 30, 2008 12:53 pm
by Mark
Dear alemrantareq,

You probably will want to search for and read about "thumbPos" in the docs.

Best,

Mark

Posted: Tue Dec 02, 2008 6:35 am
by alemrantareq
Hi mark,
thanks for your reply. I'm using windows XP and my desktop has a folder named "FiletoCopy" containing 3 files to be copied to my D: drive. My app has a progressbar named "progress" and a btn "Copy". I made the following script for that btn -

Code: Select all

on mouseUp
  put specialfolderpath(0) & "/FiletoCopy/" into sfolder
  put "D:/" into dfolder
  set the directory to sfolder
  put the files into flist
  filter flist with ".*"
  set the endvalue of scrollbar "progress" to the number of lines in flist
  repeat with n = 1 to the number of lines in flist
    set the thumbpos of scrollbar "progress" to n
    put sfolder & line n of flist into sfile
    put dfolder & line n of flist into dfile
    revcopyfile sfile,dfile
  end repeat
end mouseUp
This script doesn't work. Have I missed anything? please, complete this script.

Posted: Tue Dec 02, 2008 11:54 am
by Mark
Dear alemrantareq,

What exactly does "doesn't work" mean? What happens? Are you sure that all your file names start with a period?

Best,

Mark

Posted: Thu Dec 04, 2008 7:57 am
by alemrantareq
Oh, I've made a mistake; as I use windows, the correct line will be -

Code: Select all

filter flist with "*."
inspite of -

Code: Select all

filter flist with ".*"
According to my script, the sb's thumbposition increases according to the number of files. If the files are five, it reach to the end in five steps. Now, I want to copy a large file of 1.5 GB using the sb. As the number of file is one, the sb reaches to the end at once while that file still coping. I need to increase the thumbpos of sb according to the percentage of coping that file. What will be the script? Pls, do it with my script.....Thanks in advance.

Posted: Thu Dec 04, 2008 10:43 am
by Mark
Dear alemrantareq,

First, you need to get the filesize of the file to read. Second, you open the file for binary read. Third, open the destination file for binary write. Fourth, use a repeat loop to read 10K, or 100K, from the first file and write it to the second file. With each repeat loop, you calculate the amount of data read as a percentage of the file size and set the thumbPos of the slider to that value (the endValue of the slider has to be 100). Stop the repeat loop when the it variable contains empty or the result contains EOF. Fifth, close the two files.

Here is a script to get the file size.

Code: Select all

function fileSize theFile
  put the defaultFolder into myOldDfltFolder
  set the itemDel to "/"
  set the defaultFolder to (item 1 to -2 of theFile)
  put the detailed files into myFileInfo
  put line (lineOffset(urlEncode(last item of theFile),myFileInfo)) of myFileInfo into myFileInfo
  set the itemDel to comma
  put (item 2 of myFileInfo + item 3 of myFileInfo) into myFileInfo
  set the defaultFolder to myOldDfltFolder
  return myFileInfo
end fileSize
Best regards,

Mark

Posted: Sat Dec 06, 2008 5:10 am
by alemrantareq
Hi Mark,
Thanks for your reply. I want to copy a file "Help Me.mpg" from my desktop to D: drive. Here's the script I made -

Code: Select all

on mouseUp
  put specialfolderpath(0) & "/Help Me.mpg" into oldFile
  put "D:/Help Me.mpg" into newFile
  open file newFile
  open file oldFile
  read from file oldfile until eof
  put it into tdata
end mouseUp
I can't understand if I've to make any change in your script to get the file size of that file and how to use a repeat loop to read 10K, or 100K, from the first file and write it to the second file?

Posted: Sat Dec 06, 2008 10:53 am
by Mark
Hi alemrantareq,

Your script is a first move into the right direction. As I wrote in my previous message, the repeat loop starts right after you open both files.

Youare currently reading the entire file at once. Don't read the file until EOF at once. EOF means "end of file". You can read about this in the documentation. In the docs, you will also find how you can read smaller chunks of a file. For example, you can read 5 characters at the same time by using the code

Code: Select all

read from file myFilePath for 5
I suggest you open the docs and read about the read command now.

Try to follow the steps in my previous e-mail, don't forget to close the repeat loop, if the result contains "eof" after the read command.

If you post your script with a repeat loop, I'll gladly help you with the next step.

Best regards,

Mark