- Hands-On Penetration Testing with Python
- Furqan Khan
- 194字
- 2021-07-02 14:14:01
Renaming and deleting files and accessing directories
In Python, system-level access to file directories and various other operating system commands is provided by the os module. The os module is a very powerful utility. In this section, we will see a few of its uses with respect to renaming, deleting, creating, and accessing directories with the help of the following snippet from the os_directories.py file:

The code snippet in the preceding screenshot shows the various ways in which the os module is used with files and directories in Python, in order to rename and delete files and create and change directories. It also showed us how we can rename and traverse all the files (including nested files) from a subfolder. It should be noted that if we wish to delete a folder, we can use the os.rmdir() method, but all the files of the folder should be explicitly deleted in order for this to work:
- The following output shows what happens with the file before and after its creation:

- The following output shows the change in the file name:

- The following output shows the change after the file is removed:

- LabVIEW 2018 虛擬儀器程序設(shè)計(jì)
- 碼上行動(dòng):零基礎(chǔ)學(xué)會(huì)Python編程(ChatGPT版)
- AngularJS深度剖析與最佳實(shí)踐
- Mastering Python High Performance
- Monitoring Elasticsearch
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- Jenkins Continuous Integration Cookbook(Second Edition)
- 移動(dòng)界面(Web/App)Photoshop UI設(shè)計(jì)十全大補(bǔ)
- Learning R for Geospatial Analysis
- Python深度學(xué)習(xí)原理、算法與案例
- Unity 2018 Augmented Reality Projects
- Oracle實(shí)用教程
- 進(jìn)入IT企業(yè)必讀的324個(gè)Java面試題
- Akka入門(mén)與實(shí)踐
- 程序員的成長(zhǎng)課