本帖最后由 mpy2003 于 2013-11-11 13:05:17 编辑

解决方案 »

  1.   

    目前我只能这样重新过一遍,不知道有没有更好的方法
    private void watcher_Created(object sender, FileSystemEventArgs e)
    {
       foreach (ListViewItem i in this.listView.Items)
          {
               if (e.FullPath.ToString().IndexOf(i.SubItems[2].Text) > -1)
               {
                     string dataName = i.Text;
               }
          }
    }
      

  2.   

    private void watcher_Created(object sender, FileSystemEventArgs e)
    {
      Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
    }
      

  3.   

    分拆全路径。参考
    如果字符串格式为
    String str="abc#def#hijkl#mn";
    string[] s = str.Split(new char[] { '#' });
    结果就是
    s[0]="abc";
    s[1]="def";
    s[2]="hijkl";
    s[3]="mn";
      

  4.   


    private void watcher_Created(object sender, FileSystemEventArgs e)
    {
       string strDirectoryName = Path.GetDirectoryName(e.FullPath);
       this.textBox1.Text = strDirectoryName;
    }
      

  5.   

    假如设置路径是Path=C:\a\b
    得到的e.FullPath=C:\a\b\c\d\e.txt
    没有这种属性可以知道是Path=C:\a\b吗?
      

  6.   

     string a = @"C:\a\b\c\d\e.txt";
                FileInfo fileInfo = new FileInfo(a);
                Console.WriteLine(fileInfo.Directory.Parent.Parent.FullName);//输出C:\a\b
      

  7.   

    据说IO下有个类叫Path.....据说他能分析你的路径。
    你要做的只是把路径赋给Path
      

  8.   

    this.fileSystemWatcher1.Path =@“C:\a\b”;
    e.FullPath=C:\a\b\c\d\e.txt,
    string strDirectoryName = Path.GetDirectoryName(e.FullPath);
    返回就是C:\a\b\c\d
      

  9.   

    private void watcher_Created(object sender, FileSystemEventArgs e)
    {
          var path = (sender as FileSystemWatcher).Path;
    }
      

  10.   

    你本身默认的路径是this.fileSystemWatcher1.Path =@“C:\a\b”,下面还有子目录,要取主目录,用this.fileSystemWatcher1.Path就可阿,
      

  11.   

    貌似不知道有多少级的子目录时,这个不太方便用
    [/quote=引用 10 楼 starfd 的回复:]
    据说IO下有个类叫Path.....据说他能分析你的路径。
    你要做的只是把路径赋给Path
    不明白具体操作
    你没有明白我的意思再说一下我的意思:
    假如设置路径是Path=C:\a\b 
    监控得到的e.FullPath=C:\a\b\e.txt
    监控得到的e.FullPath=C:\a\b\c\e.txt
    监控得到的e.FullPath=C:\a\b\c\d\e.txt
    监控得到的e.FullPath=C:\a\b\c\d\e\f.txt
    不管路径是什么样的,有多少级目录
    最后得到监控路径Path=C:\a\b
      

  12.   

    那是不是可以获取指定级数的目录呢
    不管你得到是C:\a\b\e.txt,C:\a\b\c\e.txt
    你都只取两级目录得到C:\a\b
      

  13.   

    这是应该是可以的
    只要你得到的对应的FileSystemWatcher,并结合FileSystemEventArgs,可以拿到你想要的任何数据,如果不行,你甚至可以写个新类,继承FileSystemWatcher,并添加一些属性,来记录你想要的数据这么多楼了,楼主整理下,这个应该是可以解决的
      

  14.   

    string path = (sender as FileSystemWatcher).Path.ToString();