Page 3
1. Read a Text File
Assignment: Write a program to read a text file and print its contents.
Example Output:
Contents of the file:
Hello, this is a sample text file.
It contains multiple lines.2. Write to a Text File
Assignment: Write a program that creates a text file and writes some lines of text into it.
Example Output:
File 'output.txt' created and written successfully.3. Append to a Text File
Assignment: Write a program to append new text to an existing text file.
Example Output:
New text appended to 'output.txt' successfully.4. Copy a File
Assignment: Create a program that copies the contents of one file to another.
Example Output:
5. Move a File
Assignment: Write a program to move a file from one directory to another.
Example Output:
6. Delete a File
Assignment: Create a program that deletes a specified file.
Example Output:
7. List Files in a Directory
Assignment: Write a program that lists all files in a specified directory.
Example Output:
8. Count Lines in a File
Assignment: Create a program that counts the number of lines in a text file.
Example Output:
9. Count Words in a File
Assignment: Write a program that counts the number of words in a text file.
Example Output:
10. Count Characters in a File
Assignment: Create a program that counts the number of characters in a text file.
Example Output:
11. Search for a Word in a File
Assignment: Write a program that searches for a specific word in a text file and prints the line number(s) where it occurs.
Example Output:
12. Replace Text in a File
Assignment: Create a program that replaces all occurrences of a specified word in a text file.
Example Output:
13. Create a Directory
Assignment: Write a program that creates a new directory.
Example Output:
14. Rename a File
Assignment: Create a program that renames a specified file.
Example Output:
15. Check if a File Exists
Assignment: Write a program to check if a specified file exists and print the result.
Example Output:
16. Read a CSV File
Assignment: Create a program that reads and prints the contents of a CSV file.
Example Output:
17. Write to a CSV File
Assignment: Write a program that creates a CSV file and writes data into it.
Example Output:
18. Append to a CSV File
Assignment: Write a program to append a new row to an existing CSV file.
Example Output:
19. Read JSON File
Assignment: Create a program that reads and prints the contents of a JSON file.
Example Output:
20. Write to a JSON File
Assignment: Write a program that creates a JSON file and writes data into it.
Example Output:
21. Update a JSON File
Assignment: Write a program that updates an existing JSON file with new data.
Example Output:
22. Delete a Directory
Assignment: Create a program that deletes an empty directory.
Example Output:
23. Find and Replace in a File
Assignment: Write a program that finds and replaces a string in a file.
Example Output:
24. Write Log Messages to a File
Assignment: Create a program that logs messages to a log file with timestamps.
Example Output:
25. Read a Binary File
Assignment: Write a program that reads a binary file and prints the byte values.
Example Output:
26. Convert Text File to Uppercase
Assignment: Create a program that converts all text in a file to uppercase.
Example Output:
27. Convert Text File to Lowercase
Assignment: Write a program that converts all text in a file to lowercase.
Example Output:
28. Extract Unique Lines from a File
Assignment: Create a program that extracts unique lines from a text file and saves them to a new file.
Example Output:
29. Merge Multiple Files
Assignment: Write a program that merges multiple text files into a single file.
Example Output:
30. Split a File into Smaller Files
Assignment: Create a program that splits a large file into smaller files of specified size.
Example Output:
31. Create a Summary of a Text File
Assignment: Write a program that summarizes the contents of a text file by counting words, lines, and characters.
Example Output:
32. Find Largest and Smallest Files in a Directory
Assignment: Create a program that finds and displays the largest and smallest files in a specified directory.
Example Output:
33. Create a File Backup
Assignment: Write a program that creates a backup copy of a specified file.
Example Output:
34. Check File Permissions
Assignment: Create a program that checks and prints the permissions of a specified file.
Example Output:
35. Search for Files by Extension
Assignment: Write a program that searches for files with a specific extension in a directory.
Example Output:
36. Extract Emails from a Text File
Assignment: Create a program that extracts all email addresses from a text file and saves them to another file.
Example Output:
37. Remove Empty Lines from a File
Assignment: Write a program that removes all empty lines from a text file.
Example Output:
38. Convert Line Endings in a File
Assignment: Create a program that converts Windows line endings to Unix line endings in a text file.
Example Output:
39. Create a CSV Summary Report
Assignment: Write a program that generates a summary report from a CSV file.
Example Output:
40. Validate JSON Format
Assignment: Create a program that checks if a JSON file is properly formatted.
Example Output:
41. Read XML File
Assignment: Write a program that reads and prints the contents of an XML file.
Example Output:
42. Write XML File
Assignment: Create a program that writes data to an XML file.
Example Output:
43. Extract Data from XML File
Assignment: Write a program that extracts specific data from an XML file.
Example Output:
44. Check Disk Space Usage
Assignment: Create a program that checks and prints the available disk space on the system.
Example Output:
45. Monitor File Changes
Assignment: Write a program that monitors a file for changes and logs them.
Example Output:
46. Create a File Tree Structure
Assignment: Create a program that generates a tree structure of files and directories.
Example Output:
47. Encrypt and Decrypt a File
Assignment: Write a program that encrypts a file and then decrypts it.
Example Output:
48. Generate a Random File Name
Assignment: Create a program that generates a random file name for saving a file.
Example Output:
49. Backup Multiple Files
Assignment: Write a program that creates backups of multiple specified files.
Example Output:
50. Sync Two Directories
Assignment: Create a program that synchronizes two directories, copying new and updated files.
Example Output:
Last updated