123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace 空白文件生成器
- {
- public partial class Form1 : Form
- {
- long size = 0;
- public Form1()
- {
- InitializeComponent();
- label7.Text = trackBar1.Value.ToString();
- numericUpDown1.Increment = trackBar1.Value;
- }
- private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form form = new AboutBox1();
- form.ShowDialog();
- }
- private void trackBar1_ValueChanged(object sender, EventArgs e)
- {
- label7.Text = trackBar1.Value.ToString();
- numericUpDown1.Increment = trackBar1.Value;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
- {
- textBox1.Text = folderBrowserDialog1.SelectedPath;
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- label555:
- if (Directory.Exists(textBox1.Text))
- {
- if (label2.Text != "")
- {
- if (comboBox1.Text != "")
- {
- if (numericUpDown1.Value > 0)
- {
- if (comboBox2.Text != "")
- {
- string path=textBox1.Text+@"\"+textBox2.Text+"."+comboBox1.Text;
- if (comboBox2.Text == "B")
- {
- size = (int)numericUpDown1.Value;
- }
- if (comboBox2.Text == "KB")
- {
- size = (int)numericUpDown1.Value*1024;
- }
- if (comboBox2.Text == "MB")
- {
- size = (int)numericUpDown1.Value * 1024 * 1024;
- }
- if (comboBox2.Text == "GB")
- {
- size = (long)numericUpDown1.Value * 1024 * 1024 * 1024;
- }
- if (MessageBox.Show("文件地址:"+path+ "\r\n文件大小:" + size.ToString(), "确认信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- {
- Process process = new Process();
- process.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
- process.StartInfo.CreateNoWindow = true; //是否在新窗口中启动该进程的值 (不显示程序窗口)
- process.StartInfo.RedirectStandardInput = true; // 接受来自调用程序的输入信息
- process.StartInfo.RedirectStandardOutput = true; // 由调用程序获取输出信息
- process.StartInfo.RedirectStandardError = true; //重定向标准错误输出
- process.StartInfo.FileName = "cmd.exe";
- process.Start(); // 启动程序
- process.StandardInput.WriteLine("fsutil file createnew " + path + " " + size); //向cmd窗口发送输入信息
- process.StandardInput.AutoFlush = true;
- // 前面一个命令不管是否执行成功都执行后面(exit)命令,如果不执行exit命令,后面调用ReadToEnd()方法会假死
- process.StandardInput.WriteLine("exit");
- StreamReader reader = process.StandardOutput;//获取exe处理之后的输出信息
- string curLine = reader.ReadLine(); //获取错误信息到error
- int line = 0;
- while (!reader.EndOfStream)
- {
- if (!string.IsNullOrEmpty(curLine))
- {
- line++;
- if (line == 4)
- {
- MessageBox.Show(curLine, "生成结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- curLine = reader.ReadLine();
- }
- reader.Close(); //close进程
- process.WaitForExit(); //等待程序执行完退出进程
- process.Close();
- }
- }
- else
- {
- MessageBox.Show("文件大小单位无效,请重新选择文件单位", "生成失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("文件大小无效,请重新输入文件大小", "生成失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("文件扩展名无效,请重新输入或选择扩展名", "生成失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("文件名无效,请重新输入文件名", "生成失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- if (textBox1.Text != "")
- {
- DirectoryInfo directoryInfo = new DirectoryInfo(textBox1.Text);
- directoryInfo.Create();
- goto label555;
- }
- else
- {
- MessageBox.Show("位置无效,请重新输入路径或浏览文件夹", "生成失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- }
|