win搜索文件搜不到含有括号的的图片,例如(2).png 搜索不到括号,解决,System.FileName:~=“(”

博客介绍了Win7系统中搜索文件名带圆括号文件的方法,使用System.FileName:~=“(”即可,同时说明了~=表示包含、~<表示以什么为开头、=表示以什么为名、~!表示不包含等搜索符号的含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

win7搜索文件怎么搜索文件名中带圆括号的文件

System.FileName:~=“(” 这样就行。 括号上加个引号windows

~= 是包含的意思,

~< 是以什么为开头,

= 是以什么为名,

~! 是不包含

如下搜索的时候加下面一整串

System.FileName:~=“(” 

在这里插入图片描述
在这里插入图片描述

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _2 { public partial class Addnotepoint : Form { public Addnotepoint() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void Addnotepoint_Load(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void pcbtn_Click(object sender, EventArgs e) { this.Close(); } private void pabtn_Click(object sender, EventArgs e) { //如果文本框内容为空,返回 if(textBox1.Text.Trim() == "" || textBox2.Text.Trim() == ""|| textBox4.Text.Trim() == "" || richTextBox1.Text.Trim() == ""|| dateTimePicker1.Text =="") { MessageBox.Show("有空项", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 在插入前添加输入验证 if (string.IsNullOrWhiteSpace(textBox1.Text) || !int.TryParse(textBox1.Text, out _)) { MessageBox.Show("PID必须为有效整数"); return; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { MessageBox.Show("Pname不能为空"); return; } if (dateTimePicker1.Value > DateTime.Now) { MessageBox.Show("保存日期不能是未来时间"); return; } Dao2 dao = new Dao2(); dao.Connect(); // 确保连接已打开 // 使用参数化查询并指定实际字段名 string sql = @" INSERT INTO T_Point (Pid, Pname, Stype, [Content], Savedate, Image) VALUES (@Pid, @Pname, @Stype, @Content, @Savedate, @Image)"; // 创建参数列表,使用实际字段名作为参数名 List<SqlParameter> parameters = new List<SqlParameter> { // Pid - 假设是整数类型 new SqlParameter("@Pid", SqlDbType.Int) { Value = int.Parse(textBox1.Text) }, // Pname - 文本类型 new SqlParameter("@Pname", SqlDbType.NVarChar) { Value = textBox2.Text }, // Stype - 文本类型 new SqlParameter("@Stype", SqlDbType.NVarChar) { Value = textBox4.Text }, // [Content] - 注意Content是SQL关键字,需要用方括号包裹 new SqlParameter("@Content", SqlDbType.NVarChar) { Value = richTextBox1.Text }, // Savedate - 日期类型 new SqlParameter("@Savedate", SqlDbType.DateTime) { Value = dateTimePicker1.Value }, // 添加图片参数 new SqlParameter("@Image", SqlDbType.VarBinary) { Value = _imageData ?? (object)DBNull.Value } }; // 执行SQL命令 int n = dao.ExecuteParameterized(sql, parameters); if (n > 0) { MessageBox.Show("添加成功"); this.Close(); // 添加这行代码关闭窗口 } else { MessageBox.Show("添加失败"); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void richTextBox1_TextChanged(object sender, EventArgs e) { } private void btnSelectImage_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp"; openFileDialog.Title = "选择图片"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; try { // 检查文件是否存在 if (!File.Exists(filePath)) { MessageBox.Show($"文件不存在: {filePath}"); return; } // 检查文件大小限制(例如 2MB) FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Length > 2 * 1024 * 1024) // 2MB { MessageBox.Show("图片大小不能超过 2MB"); return; } // 读取图片文件为字节数组 _imageData = File.ReadAllBytes(filePath); // 在PictureBox中显示图片 - 使用内存流避免文件锁定 using (MemoryStream ms = new MemoryStream(_imageData)) { pictureBox1.Image = Image.FromStream(ms); } lblImageStatus.Text = $"已选择图片 ({fileInfo.Length / 1024} KB)"; } catch (FileNotFoundException ex) { MessageBox.Show($"文件不存在: {ex.FileName}"); _imageData = null; } catch (PathTooLongException) { MessageBox.Show("文件路径过长,请将文件移动到较短的路径下"); _imageData = null; } catch (UnauthorizedAccessException) { MessageBox.Show("没有权限访问该文件"); _imageData = null; } catch (IOException ex) { MessageBox.Show($"文件读取错误: {ex.Message}"); _imageData = null; } catch (Exception ex) { MessageBox.Show($"加载图片失败: {ex.Message}"); _imageData = null; } finally { // 如果读取失败,清除图片预览 if (_imageData == null) { pictureBox1.Image = null; lblImageStatus.Text = "未选择图片"; } } } } } } } 报错:不存在_imageData
最新发布
07-04
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _2 { public partial class Addnotepoint : Form { // 存储图片的字节数组 private byte[] _imageData = null; public Addnotepoint() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void Addnotepoint_Load(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void pcbtn_Click(object sender, EventArgs e) { this.Close(); } private void pabtn_Click(object sender, EventArgs e) { //如果文本框内容为空,返回 if(textBox1.Text.Trim() == "" || textBox2.Text.Trim() == ""|| textBox4.Text.Trim() == "" || richTextBox1.Text.Trim() == ""|| dateTimePicker1.Text =="") { MessageBox.Show("有空项", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 在插入前添加输入验证 if (string.IsNullOrWhiteSpace(textBox1.Text) || !int.TryParse(textBox1.Text, out _)) { MessageBox.Show("PID必须为有效整数"); return; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { MessageBox.Show("Pname不能为空"); return; } if (dateTimePicker1.Value > DateTime.Now) { MessageBox.Show("保存日期不能是未来时间"); return; } Dao2 dao = new Dao2(); dao.Connect(); // 确保连接已打开 // 使用参数化查询并指定实际字段名 string sql = @" INSERT INTO T_Point (Pid, Pname, Stype, [Content], Savedate, Image) VALUES (@Pid, @Pname, @Stype, @Content, @Savedate, @Image)"; // 创建参数列表,使用实际字段名作为参数名 List<SqlParameter> parameters = new List<SqlParameter> { // Pid - 假设是整数类型 new SqlParameter("@Pid", SqlDbType.Int) { Value = int.Parse(textBox1.Text) }, // Pname - 文本类型 new SqlParameter("@Pname", SqlDbType.NVarChar) { Value = textBox2.Text }, // Stype - 文本类型 new SqlParameter("@Stype", SqlDbType.NVarChar) { Value = textBox4.Text }, // [Content] - 注意Content是SQL关键字,需要用方括号包裹 new SqlParameter("@Content", SqlDbType.NVarChar) { Value = richTextBox1.Text }, // Savedate - 日期类型 new SqlParameter("@Savedate", SqlDbType.DateTime) { Value = dateTimePicker1.Value }, // 添加图片参数 new SqlParameter("@Image", SqlDbType.VarBinary) { Value = _imageData ?? (object)DBNull.Value } }; // 执行SQL命令 int n = dao.ExecuteParameterized(sql, parameters); if (n > 0) { MessageBox.Show("添加成功"); this.Close(); // 添加这行代码关闭窗口 } else { MessageBox.Show("添加失败"); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void richTextBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp"; openFileDialog.Title = "选择图片"; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { string filePath = openFileDialog.FileName; // 读取图片文件为字节数组 _imageData = File.ReadAllBytes(filePath); // 在PictureBox中显示图片 pictureBox1.Image = Image.FromFile(filePath); lblImageStatus.Text = "已选择图片"; } catch (Exception ex) { MessageBox.Show($"加载图片失败: {ex.Message}"); _imageData = null; } } } } private void lblImageStatus_Click(object sender, EventArgs e) { } } } 报错:_imageData = File.ReadAllBytes(filePath);File不存在
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值