سلام دوست عزیز
خدم دویروز که مطلب شما رو خوندم یه ایده داشتم که با استفاده از دایرکتوری این کارو بکنیم اما الان یه سورس پیدا کردم که فک کنم مشکل شما رو حل بکنه و اینکه خواستید اسم رو عوض کنید میتونید یه تکست باکس بزارید و هر نامه رو خواستید چک کنید
یه فرم باز کن و اینارو همینطوری بریز داخلش فرم هیچی نمیخاد
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
using System.Linq;
using System.IO;
using UsbLibrary;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool Is_Flash = false;
string Drive_name = "NO";
string File_Name = "test";
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
usbHidPort1.ParseMessages(ref m);
base.WndProc(ref m);
}
private void Form1_Load(object sender, EventArgs e)
{
Get_Removable_Drives();
Thread myth;
myth = new Thread(new ThreadStart(usbHidPort1_OnDeviceArrived));
myth.Start();
Thread.Sleep(100);
}
private void usbHidPort1_OnDeviceArrived()
{
if (Is_Flash == true && Drive_name !="NO")
MessageBox.Show($"File in drive---That's Name is==>{0} "+File_Name, "Mesage For Drive");
else if (Is_Flash == true && Drive_name == "NO")
MessageBox.Show("File Not Found");
}
private void usbHidPort1_OnDeviceRemoved(object sender, EventArgs e)
{
if (Is_Flash == true && Drive_name != "No")
MessageBox.Show("bye");
Is_Flash = false;
Drive_name = "No";
}
public void Get_Removable_Drives()
{
string RMDRV = "";
Is_Flash = false;
Drive_name = "No";
foreach (DriveInfo DRV in DriveInfo.GetDrives())
{
RMDRV = DRV.DriveType.ToString();
if (RMDRV == "Removable")
{
Is_Flash = true;
if (File.Exists(DRV.Name + @"01.txt"))
{
System.Diagnostics.Process.Start(DRV.Name + File_Name);
Drive_name = DRV.Name;
break;
}
}
}
this.Hide();
}
private void notifyIcon1_Click(object sender, EventArgs e)
{
}
}
}