saya menggunakan skrip berikut di google colab, coba di modifikasi agar menampilkan KB,…
- User
saya menggunakan skrip berikut di google colab, coba di modifikasi agar menampilkan KB, MB, dan atau GB pada bagian
Cetak informasi
print(f"Copied: {source_file_name} ({source_file_size} bytes) to {destination_file_name} ({destination_file_size} bytes)")
contoh output yang keluar di google colab seperti ini Copied: TEST-363.mp4 (4530758356 bytes) to TEST-363.mp4 (4530758356 bytes)
import shutil import os from tqdm.notebook import tqdm
Fungsi untuk menyalin file dengan progress bar
def copy_with_progress(src, dst, buffer_size=1024*1024): total_size = os.path.getsize(src) with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: with tqdm(total=total_size, unit='B', unit_scale=True, desc=os.path.basename(src), leave=False) as pbar: while True: buf = fsrc.read(buffer_size) if not buf: break fdst.write(buf) pbar.update(len(buf))
Fungsi untuk mendapatkan informasi file
def get_file_info(filepath): file_size = os.path.getsize(filepath) file_name = os.path.basename(filepath) return file_name, file_size
Tentukan path tujuan di Google Drive
DRIVE = "/content/drives/barcu/DEEL/" #@param {type:"string"}
Cek jika directory tujuan ada, jika tidak buat directory tersebut
if not os.path.exists(DRIVE): os.makedirs(DRIVE)
Ambil semua file .mp4 di /content
mp4_files = [f for f in os.listdir("/content") if f.endswith(".mp4")]
Loop melalui semua file .mp4 di /content dengan progress bar
for file in tqdm(mp4_files, desc="Copying files", unit="file"): source_file = os.path.join("/content", file) destination_file = os.path.join(DRIVE, file)
# Salin file dari source ke destination dengan progress bar copy_with_progress(source_file, destination_file) # Mendapatkan informasi file source_file_name, source_file_size = get_file_info(source_file) destination_file_name, destination_file_size = get_file_info(destination_file) # Hapus file asli setelah disalin os.remove(source_file) # Cetak informasi print(f"Copied: {source_file_name} ({source_file_size} bytes) to {destination_file_name} ({destination_file_size} bytes)") - Assistant
- User
bisakah patoolib menampilkan progress bar ketika mengekstrak file archive? saya menggunakan skrip berikut di google colab
SPTH = "/content/better_test-file.part1.rar" # @param {type:"string"} DPTH = "/content/" # @param {type:"string"}
import patoolib
patoolib.extract_archive(SPTH, outdir=DPTH)
- Assistant