소스 검색

解决路径不存在时自动新建文件夹.

dail 4 년 전
부모
커밋
9f5d07d6ab

BIN
.vs/MOTINOVA_Motor_Factory_Set/v16/.suo


+ 7 - 1
ExportForm.cs

@@ -19,6 +19,9 @@ namespace MOTINOVA_Motor_Factory_Set
         Dictionary<string, UInt16> MotorParam = new Dictionary<string, UInt16>();
         Dictionary<string, string> Otherinfo = new Dictionary<string, string>();
 
+        //文件路径
+        string FilePath = "cfg\\";
+
         public ExportForm()
         {
             InitializeComponent();
@@ -388,7 +391,10 @@ namespace MOTINOVA_Motor_Factory_Set
             {
                 textBox_Client.Text = "STD";
             }
-            using (StreamWriter file = new StreamWriter("cfg\\" + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_Remark.Text + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ttcfg"))
+
+            if (System.IO.Directory.Exists(FilePath) == false)
+                System.IO.Directory.CreateDirectory(FilePath);
+            using (StreamWriter file = new StreamWriter(FilePath + textBox_Model.Text + "_" + textBox_Client.Text + "_" + textBox_Remark.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".ttcfg"))
             {
                 //用户参数1
                 file.WriteLine("[{0}]", "用户参数1");

+ 10 - 2
ImportForm.cs

@@ -82,6 +82,10 @@ namespace MOTINOVA_Motor_Factory_Set
         {
             //装载配置文件
             CfgFilePath = System.IO.Directory.GetCurrentDirectory() + "\\cfg\\";
+            if (System.IO.Directory.Exists(CfgFilePath) == false)
+            {
+                System.IO.Directory.CreateDirectory(CfgFilePath);
+            }
             var files = Directory.GetFiles(CfgFilePath, "*.ttcfg");
             comboBox_File.Items.Clear();
             foreach (var file in files)
@@ -1193,13 +1197,17 @@ namespace MOTINOVA_Motor_Factory_Set
             Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
             Graphics g = Graphics.FromImage(bit);
             g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片  
-            LogSaveFileName = System.IO.Directory.GetCurrentDirectory() + "\\log\\";
+            LogSaveFileName = System.IO.Directory.GetCurrentDirectory() + "\\log_" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
+            if (System.IO.Directory.Exists(LogSaveFileName) == false)
+                System.IO.Directory.CreateDirectory(LogSaveFileName);
             LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_测试记录" + ".png";
             bit.Save(LogSaveFileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
 
             //一键导出数据
             //设置保存路径
-            LogSaveFileName = System.IO.Directory.GetCurrentDirectory() + "\\log\\";
+            LogSaveFileName = System.IO.Directory.GetCurrentDirectory() + "\\log_" + DateTime.Now.ToString("yyyy-MM-dd").Replace("/", "-") + "\\";
+            if (System.IO.Directory.Exists(LogSaveFileName) == false)
+                System.IO.Directory.CreateDirectory(LogSaveFileName);
             LogSaveFileName += textBox_PDinfo.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_ParamsLog" + ".ttlog";
 
             //开始发送指令

+ 6 - 1
ManageForm.cs

@@ -36,6 +36,8 @@ namespace MOTINOVA_Motor_Factory_Set
                 button_Delete.Visible = true;
                 button_OpenFile.Visible = true;
 
+                if (System.IO.Directory.Exists(FilePath) == false)
+                    System.IO.Directory.CreateDirectory(FilePath);
                 ListFileRefresh(FilePath);
             }
             else
@@ -53,7 +55,8 @@ namespace MOTINOVA_Motor_Factory_Set
             {
                 listBox_File.Items.Add(Path.GetFileName(file));
             }
-            listBox_File.SelectedIndex = 0;
+            if (listBox_File.Items.Count != 0)
+                listBox_File.SelectedIndex = 0;
         }
 
         private void button_Delete_Click(object sender, EventArgs e)
@@ -66,6 +69,8 @@ namespace MOTINOVA_Motor_Factory_Set
                 if (MessageBox.Show("确认删除?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
                     File.Delete(FilePath + "\\" + SelectFile);
+                    if (System.IO.Directory.Exists(FilePath) == false)
+                        System.IO.Directory.CreateDirectory(FilePath);
                     ListFileRefresh(FilePath);
                 }
             }

BIN
bin/Debug/MOTINOVA_Motor_Factory_Set.exe


BIN
bin/Debug/MOTINOVA_Motor_Factory_Set.pdb


BIN
bin/Debug/发布文件/MOTINOVA_Motor_Factory_Set.exe


BIN
bin/Debug/发布文件/MOTINOVA_Motor_Factory_Set.pdb


BIN
bin/Debug/发布文件/MOTINOVA_Motor_Factory_Set_20210428.exe


BIN
bin/Debug/发布文件/使用说明.docx


BIN
bin/Debug/发布文件/使用说明.pdf


BIN
obj/Debug/DesignTimeResolveAssemblyReferences.cache


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.csprojAssemblyReference.cache


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.exe


BIN
obj/Debug/MOTINOVA_Motor_Factory_Set.pdb