Copy files using progress bar
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 203
- Joined: Wed Jul 23, 2008 8:46 am
Copy files using progress bar
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...
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...
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
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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 203
- Joined: Wed Jul 23, 2008 8:46 am
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.
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.
-
- Posts: 203
- Joined: Wed Jul 23, 2008 8:46 am
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 -
This script doesn't work. Have I missed anything? please, complete this script.
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
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
What exactly does "doesn't work" mean? What happens? Are you sure that all your file names start with a period?
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 203
- Joined: Wed Jul 23, 2008 8:46 am
Oh, I've made a mistake; as I use windows, the correct line will be -
inspite of -
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.
Code: Select all
filter flist with "*."
Code: Select all
filter flist with ".*"
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.
Best regards,
Mark
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
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 203
- Joined: Wed Jul 23, 2008 8:46 am
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 -
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?
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
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
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
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
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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode