【#第一文档网# 导语】以下是®第一文档网的小编为您整理的《自己编写一个小病毒代码》,欢迎阅读!
C# 代码 自己编写一个小程序,类是病毒但无害,就是会创建50*50*26个空文件夹,运行过产生30000个文件夹就等不下去了,删除新建的文件夹估计要10分钟,仅为娱乐 private void button4_Click(object sender, EventArgs e) { IList<string> temp_list = new List<string>(); string path = "I:\\新建文件夹";/****本人笔记本有I盘,同时为了删除方便****/ // string path = "C:\\ Program Files"; 用这行代码时估计你要崩溃 string pathFile = ""; char [] arry = new char[26] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' }; try { for (int p = 0; p < 50; p++) { for (int k = 0; k < 50; k++) { for (int i = 0; i < 26; i++) { temp_list.Add(i.ToString()); //temp_list.Add("num:" + i.ToString()); } temp_list = getListItems(temp_list, 26); for (int i = 0; i < temp_list.Count; i++) { richTextBox1.Text += arry[int.Parse(temp_list[i])]; pathFile += arry[int.Parse(temp_list[i])]; if (Directory.Exists(path + "\\" + pathFile))/***判断文件夹是否存在,存在就删除该文件加***/ { Directory.Delete(path + "\\" + pathFile); System.IO.Directory.CreateDirectory(path + "\\" + pathFile);/****创建文件加*****/ } else { System.IO.Directory.CreateDirectory(path + "\\" + pathFile); /****创建文件加*****/ } richTextBox2.Text += temp_list[i]; if (pathFile.Length > 200)/***文件夹的名字超过240字符后会报错,故取240以内都有效***/ { pathFile = ""; } } } } } catch (Exception ee) { throw new Exception(ee.ToString()); } } public static IList<string> getListItems(IList<string> list, int num)/***建立获取随机数****/ { IList<string> temp_list = new List<string>(list); IList<string> return_list = new List<string>(); Random random = new Random(); for (int i = 0; i < num; i++) { if (temp_list.Count > 0) { int arrIndex = random.Next(0, temp_list.Count); return_list.Add(temp_list[arrIndex]); temp_list.RemoveAt(arrIndex); } else { break; } } return return_list; } 本文来源:https://www.dywdw.cn/50ed4e4fcf84b9d528ea7aff.html