So I am trying to do something in visual basic I start learning but still that is not enough. Mostly I am using codes from internet. Now I want to copy few files from first folder to second folder and overwrite existing files and I want to see progress on progress bar (all files together are about 2GB)
SOLVED: I found source code for some program and used some parts to make this work
Tshepang
6,3541818 gold badges7474 silver badges114114 bronze badges
user1959879user1959879
1 Answer
Here is my favorite way of doing it.. Using the
SHFileOperation API
This API will automatically show the progress as shown in the screenshot below.
Here is an example. Paste this code in a module
and then copy files or folders like this
Screenshot
Siddharth RoutSiddharth Rout
120k1414 gold badges162162 silver badges216216 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Not the answer you're looking for? Browse other questions tagged vbafile-ioprogress-bar or ask your own question.
Otherwise, is there any alternative command line utility that can achieve this?
Ciro Santilli 新疆改造中心996ICU六四事件
11.2k55 gold badges5252 silver badges5454 bronze badges
Olivier LalondeOlivier Lalonde
21.8k5151 gold badges112112 silver badges142142 bronze badges
18 Answers
While
cp hasn't got this functionality, you can use pv to do this:
Note: this method will lose the file's permissions and ownership. Files copied this way will have the same permissions as if you'd created them yourself and will belong to you.
In this example,
pv basically just outputs the file to stdout*, which you redirect to a file using the > operator. Simultaneously, it prints information about the progress to the terminal when you do that.
This is what it looks like:
You may need to Install pv (alternatively, type
sudo apt-get install pv ) on your system.
*: The technical bit
There are three important streams of data in a unix-like system: stdout (standard output), stderr (standard error) and stdin (standard input). Every program has all three, so to speak. The
> redirection operator redirects program output to a file. Without arguments, as you see above, > redirects a program's standard output to a file. cp basically does nothing fancier than
(where
cat just reads a file and prints it to stdout). pv is just like cat, but if you redirect it's output stream somewhere else, it will print progress information to stdout instead.
Take a look at
man pv to learn more about it.
Another option, as DoR suggests in this answer, is to use rsync instead:
This will preserve the files permissions/ownership while showing progress.
Stefano Palazzo♦Stefano Palazzo
65.3k3535 gold badges184184 silver badges218218 bronze badges
There isn't. See here as to why. Although it does more than you need,
rsync has a --progress parameter. The -a will keep permissions,etc, and -h will be human readable.
The output will look something like this:
bartekbrakbartekbrak
2,58511 gold badge1111 silver badges2020 bronze badges
If you want to see if your files are transferring correctly you could use
gcp and gcp is like cp but by default gives you a progress bar so that you can see what is being copied. As the program's wiki notes, gcp has several useful features such as
However, even when the progress bar has reached 100% when using the tool, you must wait until your terminal prompt reappears before safely removing your media so that you can ensure that the transfer process has successfully finished.
gcp is used to copy files and has options such as --preserve so that various attributes and permissions can be preserved and --recursive so that whole directories can be copied. More information on its options can be found by entering man gcp or by going to the Ubuntu manpages online. A tutorial is also available on this site.
Install
gcp from the repositories with
(Note: in Ubuntu 12.10 the new automount point is, for example,
/media/user/usbdisk )
You can copy a file to your media by entering
and copy a folder to your media with
Sample output from
gcp with the progress bar:
You can of course specify multiple files or folders to copy to your disk, and there are a lot of other options covered in
man gcp .
user76204
I get a kick out of using cURL for this exact purpose. The man page lists the 'FILE' protocol as supported, so just use it like any other protocol in a URL:
Speed, progress, time remaining, and more -- all in a familiar format.
mathemagicianmathemagician
While it doesn't display speed, when copying multiple files, the BuZZ-dEE
-v option to the cp command will provide you with progress info. e.g.
9,4551212 gold badges5252 silver badges7171 bronze badges
UbuntouristUbuntourist
The kernel knows most of the data such as speed, and often also percentage. Modern kernels expose this via their /proc filesystem.
showspeed from https://github.com/jnweiger/showspeed uses that info. It can attach to already running programs and give periodic updates like this:
Community♦
Jürgen WeigertJürgen Weigert
There is a tool called
progress in the repositories that is able to examine various different commands and display progress info for them.
Install it using the command
This tool can be used like that:
Output:
Byte Commander♦
69.7k2727 gold badges189189 silver badges318318 bronze badges
Nathaniel A MalinowskiNathaniel A Malinowski
There's a new tool called cv that can find any descriptor related to a running command and show progress and speed:https://github.com/Xfennec/cv
outputs the stats for all running cp,mv etc. operations
naugturnaugtur
While
pv can deal with local cp tasks, using dd with pv can deal with both local (cp ) and remote (scp ) tasks.
Please ensure the
path/to/dest.mkv exits by touch path/to/dest.mkv
This can show the progress, but if you want the percentage information,
Replace
100M above with the real size of your source file.
Here Comes the Remote Part
While
scp can hardly show current progress, using dd with pv is a piece of cake.
onemachonemach
dd status=progress
Option added in GNU Coreutils 8.24+ (Ubuntu 16.04):
The terminal shows a line of type:
See also: How do you monitor the progress of dd?
Ciro Santilli 新疆改造中心996ICU六四事件Ciro Santilli 新疆改造中心996ICU六四事件
11.2k55 gold badges5252 silver badges5454 bronze badges
As many said, cp does not include this functionality.
Just to throw my $0.02, what I usually do with trivial copying situations (i.e. no
-R ):
This can keep me updated on target file size, with quite a minimum hassle.
As an alternative for less trivial situations, e.g. recursively copying directories, you can use
watch du -hs DIR to see summary of DIR size. However du can take long to compute and can even slow down the copying, so you might want to use -n INTERVAL argument to watch so that trade-off is acceptable.
Update: In case you use wild-cards with command used with watch du, e.g.
watch du -hs backup/* , don't forget to quote:
otherwise the wild-cards will be expanded only once, when watch is started so du will not look at new files / subdirectories.
Alois MahdalAlois Mahdal
If you have rsync 3.1 or higher (
rsync --version ), you can copy (cp -Rpn) while preserving permissions and ownership, recurse directories, 'no clobber,' and display overall progress (instead of just progress by file), copy rate, and (very rough) estimated time remaining with:
Note that sudo is only needed if dealing with directories/files you don't own. Also, without the
--no-i-r , the percentage may reset to a lower number at some point during the copy. Perhaps later versions of rsync will default to no-i-r with info=progress2, but it does not in the current version of 3.1.2.
I've found that the percentage and time remaining are grossly overestimated when copying to a directory that already contains files (ie. like when you would typically use cp -n 'no clobber').
S LentzS Lentz
Depending on what you want to do, Midnight Commander (
mc ) might be the answer. I'm surprised it's not been mentioned yet.
Tools like
pv or rsync are good to display progress of transfer of one huge file, but when it comes to copying whole directories/trees, mc calculates the size and then displays the progress very nicely. Plus it's available out of the box on majority of systems.
kralykkralyk
Community♦
JanJan
7,77522 gold badges2222 silver badges3434 bronze badges
one more option to preserve attributes could be (if
source is a folder it will be created in destination )
hope it may be useful to someone. To have estimated transfer time this can be acheived by doing
do -s source in advance and passing it as a -s <size> parameter to pv .
ciekawyciekawy
You can copy use any program. At the same time, you can start
sudo iotop and see the actually disk read/write speed yet without progress.
McKelvinMcKelvin
Check the source code for progress_bar in the below git repository
Also try the custom bash script package supreme
Download the deb file and install in debian based distribution or download the source files, modify and use for other distros
Functionality overview
(1)Open Apps----Firefox----Calculator----Settings Warband how to become king.
(2)Manage Files----Search----Navigate----Quick access
(3)Manage Phone----Move/Copy from phone----Move/Copy to phone----Sync folders
(4)Manage USB----Move/Copy from USB----Move/Copy to USB
Java Copy File To Another Directory
KIRAN BKIRAN B
pv knows how to watch file descriptors given a pid, whether it's cp or something else
From the documentation:
Example:
alecailalecail
Not the answer you're looking for? Browse other questions tagged command-linecoreutils or ask your own question.
I'm extremely new to Java, and have mostly just been teaching myself as I go, so I've started building an applet. I'd like to make one that can select a file from the local disk and upload it as a multipart/form-data POST request but with a progress bar. Obviously the user has to grant permission to the Java applet to access the hard drive. Now I've already got the first part working: the user can select a file using a soapergemsoapergem
JFileChooser object, which conveniently returns a File object. But I'm wondering what comes next. I know that File.length() will give me the total size in bytes of the file, but how do I send the selected File to the web, and how do I monitor how many bytes have been sent? Thanks in advance.
3,1571414 gold badges5656 silver badges102102 bronze badges
11 Answers
To check progress using HttpClient, wrap the MultipartRequestEntity around one that counts the bytes being sent. Wrapper is below:
Then implements a ProgressListener which updates a progress bar. ColinD
Remember that the progress bar update must not run on the Event Dispatch Thread.
94.8k2525 gold badges180180 silver badges191191 bronze badges
tulertuler
1,87444 gold badges2727 silver badges4040 bronze badges
A simpler countingEntity would not depend on a specific entity type but rather extend ankostisankostis
HttpEntityWrapped :
3,65822 gold badges2828 silver badges4545 bronze badges
I ended up stumbling across an open source Java uploader applet and found everything I needed to know within its code. Here are links to a blog post describing it as well as the source:
Article soapergemsoapergem
Source Code
3,1571414 gold badges5656 silver badges102102 bronze badges
The amount of bytes returned by the listener is different from the original file size. So, instead of having
transferred++ , I modified it so that transferred=len ; that is the length of the actual amount of bytes being written to the output stream. And when I compute the addition of the total bytes transferred it is equal to the actual ContentLength returned by CountingMultiPartEntity.this.getContentLength();
douggynixdouggynix
You might find this article helpful. It explains in detail using HttpClient and FileUpload, both apache projects to do what you want. It also includes code samples.
Vincent RamdhanieVincent Ramdhanie
90.7k2121 gold badges126126 silver badges175175 bronze badges
Keep in mind that the progress bar might be misleading when an intermediate component in the network (e.g., an ISP's HTTP proxy, or a reverse HTTP proxy in front of the server) consumes your upload faster than the server does.
AlexanderAlexander
7,28322 gold badges1919 silver badges2121 bronze badges
As noted by the article Vincent posted, you can use Apache commons to do this.
Little snipped
el_eduardoel_eduardo
1,53344 gold badges1414 silver badges1717 bronze badges
Just my 2c worth:
This is based off of tuler's answer(has a bug at time of writing). I modified it slightly, so here is my version of tuler and mmyers answer (I can't seem to edit their answer). I wanted to attempt to make this a bit cleaner and faster. Besides the bug(which I discuss in comments on their answer), the big issue I have with their version is that it creates a new HamyHamy
CountingOutputStream with every write. This can get very expensive in terms of memory - tons of allocations and garbage collections. Smaller issue is that is uses a delegate when it could just expand the MultipartEntity . Not sure why they chose that, so I did it in a manner I was more familiar with. If anyone knows pros/cons of the two approaches that would be great. Finally, the FilterOutputStream#write(byte[], int,int) method just calls the FilterOutputStream#write(byte) in a loop. The FOS documentation recommends subclasses overriding this behavior and making this more efficient. The best way to do that here is to let the underlying OutputStream handle the writing request.
12.6k1111 gold badges6262 silver badges8888 bronze badges
Look into HTTP Client for uploadign the file to the web. It should be able to to do that. I am unsure how to get the progress bar, but it would involve querying that API somehow.
RontologistRontologist
3,14811 gold badge1616 silver badges2323 bronze badges
Apache common is very good option.Apache common allows you to configure following things.
4,0191515 gold badges5151 silver badges7070 bronze badges
From the other answers you can just override the
AbstractHttpEntity class children or implementations public void writeTo(OutputStream outstream) method you are using if do not want to create a class.
An example using a Tunaki
FileEntity instance:
94.5k2323 gold badges215215 silver badges298298 bronze badges
user3502626user3502626
Not the answer you're looking for? Browse other questions tagged javafile-iouploadprogress-bar or ask your own question.
I am trying to track the progress of a compression progress. ATM I am doing it like this:
This works fine, but I need the thread, which is giving feedback about the progress not to be implemented in this method, but when calling it (in order to create something like a progressbar on an android device). So this is more like an architectural issue. Any ideas, on how to solve that?
JohnPlataJohnPlata
3 Answers
I meanwhile solved it via overwriting the IOUtils.copy() by adding an interface as parameter:
which is then called by something like this
The only thing, i am challenged by now, is to limit the output on the console not for each byte[4096] but for let's say each two megabyte. I tried something like this:
But that does not give me any output at all
JohnPlataJohnPlata
You should implement the copy mechanism in AsyncTask.It runs on a background thread, but you can post progress with the publishProgress method.After this you can handle these events on the UI thread with the onProgressUpdate callback of the AsyncTask.
EDIT:Example:
Java Copy File Progress Bar Software
R4ng3LIIR4ng3LII
I have a very similar solution to the one proposed by JohnPlata. I took the
copy Method from IOUtils and added two parameters: the original filesize of the file to be copied from and a listener for updating the progress. My copy happens during unpacking a .gz file and since the unpacked files are roughly 3 times bigger than the packed files I estimate the end result file size (hence the line copy(in, out, inputFile.length()*3, progressListener); ). The whole thing is Android-based, so the Listener updates a notification with the progress.
The code of the class where all of this is called looks like this:
This class also contains the interface:
Community♦
Bernd KamplBernd Kampl
62211 gold badge77 silver badges1818 bronze badges
Not the answer you're looking for? Browse other questions tagged androidcompressionprogress or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |