Related Coding Blogs

Practice Top 30 Python Programming Questions on File Compression and Archiving, TechnoVlogs

Practice Top 30 Python Programming Questions on File Compression and Archiving


Q1. Create a zip file example.zip containing a file named file1.txt.
Input: Content of file1.txt: Hello, World!
Expected Output: A zip file example.zip containing file1.txt.

Q2.  Add file1.txt and file2.txt to example.zip.
Input:  
 file1.txt: Hello, World!  
 file2.txt: Python is fun!
Expected Output: example.zip contains file1.txt and file2.txt.

Q3. List all files in example.zip.
Input: example.zip contains file1.txt and file2.txt.
Expected Output: ['file1.txt', 'file2.txt'].

Q4. Extract all files from example.zip to the current directory.
Input: example.zip contains file1.txt and file2.txt.
Expected Output: file1.txt and file2.txt are extracted.

Q5. Extract only file1.txt from example.zip.
Input: example.zip contains file1.txt and file2.txt.
Expected Output: file1.txt is extracted.

Q6. Check if file3.txt exists in example.zip.
Input: example.zip contains file1.txt and file2.txt.
Expected Output: file3.txt does not exist.

Q7. Read the content of file1.txt from example.zip without extracting it.
Input: example.zip contains file1.txt with content Hello, World!
Expected Output: Hello, World!.

Q8. Add file3.txt to an existing example.zip.
Input: file3.txt: Data compression is cool.
Expected Output: example.zip now contains file1.txt, file2.txt, and file3.txt.

Q9. Remove file2.txt from example.zip.
Input: example.zip contains file1.txt and file2.txt.
Expected Output: A new zip file with only file1.txt.

Q10. Create a password-protected zip file secure.zip.
Input: Password: 1234
Expected Output: secure.zip created with password protection.

Q11. Create a tar file example.tar containing file1.txt.
Input: Content of file1.txt: Hello, World!
Expected Output: example.tar containing file1.txt.

Q12. Add file1.txt and file2.txt to example.tar.
Input:  
 file1.txt: Hello, World!  
 file2.txt: Python is fun!
Expected Output: example.tar contains file1.txt and file2.txt.

Q13. List all files in example.tar.
Input: example.tar contains file1.txt and file2.txt.
Expected Output: ['file1.txt', 'file2.txt'].

Q14. Extract all files from example.tar to the current directory.
Input: example.tar contains file1.txt and file2.txt.
Expected Output: file1.txt and file2.txt are extracted.

Q15. Extract only file1.txt from example.tar.
Input: example.tar contains file1.txt and file2.txt.
Expected Output: file1.txt is extracted.

Q16. Create a gzipped tar file example.tar.gz containing file1.txt.
Input: Content of file1.txt: Hello, World!
Expected Output: example.tar.gz created with file1.txt.

Q17. Extract all files from example.tar.gz.
Input: example.tar.gz contains file1.txt.
Expected Output: file1.txt is extracted.

Q18. Add file3.txt to example.tar.
Input: file3.txt: Data compression is cool.
Expected Output: example.tar now contains file1.txt, file2.txt, and file3.txt.

Q19. Compress example.tar to example.tar.gz.
Input: example.tar
Expected Output: example.tar.gz created.

Q20. List all files in example.tar.gz.
Input: example.tar.gz contains file1.txt and file2.txt.
Expected Output: ['file1.txt', 'file2.txt'].

Q21. Compress file1.txt to file1.txt.gz.
Input: Content of file1.txt: Hello, World!
Expected Output: file1.txt.gz created.

Q22. Decompress file1.txt.gz to retrieve file1.txt.
Input: file1.txt.gz
Expected Output: file1.txt extracted.

Q23. Read the content of file1.txt.gz without extracting it.
Input: file1.txt.gz
Expected Output: Hello, World!.

Q24. Compress file1.txt and file2.txt into separate gzip files.
Input:  
 file1.txt: Hello, World!  
 file2.txt: Python is fun!
Expected Output: file1.txt.gz and file2.txt.gz.

Q25. Compress file1.txt to file1.txt.gz and then decompress it.
Input: file1.txt: Hello, World!
Expected Output: file1.txt extracted with the same content.

Q26. Display the original and compressed sizes of file1.txt.gz.
Input: file1.txt: Hello, World!
Expected Output: Original size: 13 bytes, Compressed size: 27 bytes.

Q27. Compress all .txt files in a folder using gzip.
Input: Folder contains file1.txt, file2.txt.
Expected Output: file1.txt.gz, file2.txt.gz.

Q28. Decompress all .gz files in a folder.
Input: Folder contains file1.txt.gz, file2.txt.gz.
Expected Output: file1.txt, file2.txt.

Q29. Verify if file1.txt.gz is valid.
Input: file1.txt.gz
Expected Output: Valid gzip file.

Q30. Compare the sizes of file1.txt.gz and example.tar.gz containing the same file
Input: file1.txt, example.tar
Expected Output: Sizes of both files displayed.

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!