Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Program of instantaneous chaos of C disk with Python

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize the program of instantaneous chaos of C disk with Python". In the daily operation, I believe that many people have doubts about how to use Python to realize the program of instant chaos of C disk. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the doubt of "how to realize the program of instant chaos of C disk with Python". Next, please follow the editor to study!

1 preface

In the tiresome daily life, in order to add fun to ordinary life, I often play jokes with my friends. In addition to real-life jokes, for program learners, there are also online jokes, so today the editor will share with you a parody of Mini Program written in python. As we all know, if the computer disk C takes up too much space, the computer will be very stuck, so this time the editor chose to make a parody of disk C. (disclaimer: this article is for learning reference only and must not be used for other purposes. )

2 preparation

This parody of Mini Program, written for the python language, in addition to several built-in modules, there is also a module for packaging py files-pyinstaller. Install by entering the following command on the command line:

Pip install pyinstaller

When the required modules are ready, import them directly.

3 create code

Import os,sys,random# import module def spoofCeate (): textList = ['', 'fooled', 'interesting', 'can you delete it', 'give up', 'laugh me to death','ha', 'don't delete it' 'be careful not to delete your folder'] # the name of the generated file path ='C:\\'# C disk path for i in range (65 random.choice 91): for o in range: text = random.choice (textList) fileName = path+chr (I) + str (o) + text # with 26 uppercase letters and 0-100 numbers Randomly generated text is named if not os.path.exists (fileName): os.mkdir (fileName) for i in range (97122): for o in range (100): text = random.choice (textList) fileName = path+chr (I) + str (o) + text # with 26 lowercase letters and 0-100 numbers Randomly generated text to name if not os.path.exists (fileName): os.mkdir (fileName) spoofCeate ()

After running this code, many folders will be created on the C disk of the computer, with the name of 26 letters + 0-100 numbers + randomly selected text. As long as you send this code to a friend, as soon as he runs it, he will unknowingly create (24024) * 100 folders under disk C. when he finds out one day, he doesn't know you did it, so it's exciting to think about it.

4 delete code

Because friendship comes first, in order not to overturn the boat of friendship, the editor wrote a program to delete all the folders created. The code is as follows:

Import os,sys# import module def spoofDelete (): textList = ['', 'fooled', 'interesting', 'can you delete it', 'give up', 'laugh me to death','ha', 'don't delete it' 'be careful not to delete your own folder'] # folder name path ='C:\\'# C disk path for i in os.listdir (path): pathNow = os.path.join (path) I) for o in textList: if o in i: print (pathNow) os.rmdir (pathNow) # Delete the folder containing the given keyword breakspoofDelete ()

5 Packaging program

Because many friends don't have a python environment on their computers, they send the code to him, and he can't run it, so the editor uses python's third-party library pyinstaller to package the code. Since only pure code files need to be packaged this time, just use the following command.

Pyinstaller-F super interesting Mini Game. Pypyinsatller-F restore .py

Finally, after being packaged into an exe file, you can send it directly to your friends.

At this point, on the "how to use Python to achieve C disk instant chaos of the program" on the end of the study, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report