LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2023, 02:34 PM   #1
piotrbujakowski
LQ Newbie
 
Registered: Jan 2017
Location: London, UK
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 0
Copy files and catalogs with bar progress [don't work]


Hi.
I try write coping with folder.
Coping works, but progress bar no and I don’t know what doing …
Thanks.

import shutil
import os
import itertools

from time import sleep
from tqdm import tqdm

# path to source directory
src_dir = '/home/piotr/.cache/'

# path to destination directory
dest_dir = '/home/piotr/.cache/0/'

# getting all the files in the source directory
files = os.listdir('/home/piotr/.cache/')

# progress bar start
for files in itertools.count():
tqdm(range('files'))
# progress bar finish

shutil.copytree('/home/piotr/.cache/', '/home/piotr/.cache/0/')
 
Old 03-23-2023, 03:57 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,259

Rep: Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338
If you don't want to reinvent the wheel:

https://github.com/jarun/advcpmv
 
Old 03-23-2023, 04:59 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,804

Rep: Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954
Untested
Code:
for x in tqdm(files):
    shutil.copyfile(src_dir+x, dest_dir+x)
    sleep(.1)

Last edited by michaelk; 03-23-2023 at 05:10 PM.
 
Old 03-25-2023, 12:01 PM   #4
piotrbujakowski
LQ Newbie
 
Registered: Jan 2017
Location: London, UK
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 0
Python 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.

============= RESTART: /home/piotr/python/copy_files/copy_files_other_3.py ============

0%| | 0/14 [00:00<?, ?it/s]
0%| | 0/14 [00:00<?, ?it/s]
Traceback (most recent call last):
File "/usr/lib/python3.11/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "/home/piotr/python/copy_files/copy_files_other_3.py", line 19, in <module>
shutil.copyfile(src_dir+x, dest_dir+x)
File "/usr/lib/python3.11/shutil.py", line 256, in copyfile
with open(src, 'rb') as fsrc:
^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: '/home/piotr/.cache/gnome-desktop-thumbnailer'

Last edited by piotrbujakowski; 03-25-2023 at 12:02 PM.
 
Old 03-25-2023, 01:27 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,804

Rep: Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954Reputation: 5954
Since you were using copytree I had thought about the possibility of subdirectories but had not included that in my simple code. You probably need to use os.walk instead of listdir.
 
Old 03-30-2023, 09:28 AM   #6
piotrbujakowski
LQ Newbie
 
Registered: Jan 2017
Location: London, UK
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 0
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
 
Old 03-30-2023, 09:55 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,788

Rep: Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001Reputation: 8001
Quote:
Originally Posted by piotrbujakowski View Post
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
Exact same thing you posted in your other thread. What do you think this tells us???
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] kicker - Relaunch task bar/ tray bar (the bar at the bottom of screen). andrewysk Linux - Newbie 3 03-18-2021 03:19 PM
LXer: Advanced Copy - Add Progress Bar To cp And mv Commands In Linux LXer Syndicated Linux News 0 10-31-2020 09:31 PM
LXer: tinyMediaManager catalogs your movie and TV files LXer Syndicated Linux News 0 06-24-2016 07:28 PM
copy files/directory and show it by progress bar (zenity/kdialog) DoME69 Programming 8 05-07-2015 09:59 AM
How to display file copy progress bar bmcneely0 Linux - General 12 02-19-2012 03:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration