Python OS Module Programs, Exercises

Python os module helps to perform operating system related the task like creating a directory, removing a directory, get the current directory, copying files, running the command etc.

1). Write a Python Program To Get The Current Working Directory.

2). Write a Python Program To Get The Environment Variable

3). Write a Python Program To Set The Environment Variable

4). Write a Python Program To Get a List Of All Environment Variable Using os.environ.

5). Write a Python Program To Create a Directory Using os.mkdir()

6). Write a Python Program To Create 10 DirecTories With a Random Name.

7). Write a Python Program To Create 10 DirecTories On a Nested Level.

8). Write a Python Program To Remove An Empty Directory Using os.rmdir()

9). Write a Python Program To Remove a Non-empty DirecTory Using

10). Write a Python Program To Join 2 paths.

11). Write a Python Program To Check The File On a Given Path.

12). Write a Python Program To Check The Directory On The Given Path

13). Write a Python Program To Get a list Of all data from the Target Path.

14). Write a Python Program To Get The Total File Count In The Target Path.

15). Write a Python Program To Get The Total Folder Count In The Target Path

16). Write a Python Program To Get The Count Of Each File Extension In The Target Path.

17). Write a Python Program To Copy The File Source Path To The Target Path.

18). Write a Python Program To Copy Specific Extension Files From The Source To The Target Path.

19). Write a Python Program To Copy 10 Files In 10 Different Nested Directories.

20). Write a Python Program To Remove The File From The Given Path.

21). Write a Python Program To remove Specific Extension Files From The Target Path.

22). Write a Python Program To Create a Backup Application.
Note: We have To filter each extension file and copy it To a specific folder.

23). Write a Python Program To Run The Windows Commands.

24). Write a Python Program To Provide Command Line Arguments.

25). Write a Python Program To Get System Version Information.

26). Write a Python Program To List Path Set Using os.get_exce_path() Method.

27). Write a Python Program To Get a Random String Using os.urandom() Method.

28). Write a Python Program To Check Read Permission On Give Path Using os.access() Method.

29). Write a python Program To Get The File Size Using os.path.getsize() Method.

30). Write a Python Program To Change The Current Working Directory.

31). Write a Python Program To Scan Target DirecTory And Print All Files Name.
Using an os.scandir() Method.

32). Write a Python Program To Create Complete Path Directories With os.mkdirs() Method.

33). Write a Python Program To Execute Any Other Python Script Using os.sysetem() Method.

34). Write a Python Program To Create a Fake Data File Of 10 Different Extensions.

35). Write a Python Program To Print Data Name, PATH, and Data Type From Target Path.
Example 1:
Name : TestFolder
Path : C:\TestFolder
Type : Folder

Example 2:
Name : testdata.txt
Path : C:\testdata.txt
Type : File

36). Write a Python Program To Print All Nested Level Files/Folders Using os.walk() Methd

37). Write a Python Program To Change File/Folder Permission Using os.chmod() Method.

38). Write a Python Program To Change File/Folder Ownership Using os.chown() Method.

39). Write a Python Program To Rename Folder Name Using os.rename() Method.

40). Write a Python Program To Rename All Folders in Path Using os.remanes() Method.

41). Write a Python Program To Change Root Directory Using os.chroot() Method.

42). Write a Python Program To CPU Count Using os.cpu_count() Method.

43). Write a Python Program To Split Files/Folders from Path Using os.path.split() Method.

44). Write a Python Program To Get Ctime of File/Folder Using os.path.getctime() Method.

45). Write a Python Program To Get The Modified Time of File/Folder Using os.path.getmtime() Method.

46). Write a Python Program To Check Given Path Exist Using os.path.exists() Method.

47). Write a Python Program To Check Given Path is Link Using os.path.islink() Method.

48). Write a Python Program To Check All States of The File Using os.stat() Method.

51). Write a Python To Provide Command Line Arguments To Python File.

52). Write a Python Program To Get Platform Information.

53). Write a Python Program To Get Python Version Info.

 

Leave a Comment