在C#.net中使用FilesystemWatcher重命名文件 [英] File rename using FilesystemWatcher in C#.net

查看:72
本文介绍了在C#.net中使用FilesystemWatcher重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的项目中,我正在使用Datagridview和上下文菜单.我从特定文件夹中填充信息.它包含文件名,文件类型和大小.当用户在datagridview中选择一行并右键单击选定的文件时,用户希望重命名文件用户将在datagridview中更改文件名,并在Particular文件夹中自动更改.如何执行此操作? I如果是",请发送代码或链接.

Hi,
In my Project, I am using Datagridview and Context Menu .I fill a information from a Particular folder .it contains file name, file Type and Size.User wants to rename a file when user select a row in the datagridview and right click on selected row on the datagridview and context Menu view..user will change the File Name in the datagridview and automatically change in the Particular folder.How to do this? Is it possible to use filewatchersystem for this task?I If "yes" Please send a code or link.

推荐答案

FileSystemWatcher与处理更改无关从用户界面.它旨在监视文件系统的更改(因此而得名).您的应用程序需要驱动逻辑来重命名文件-换句话说,它需要执行File.Move将文件从一个文件名重命名为另一个文件名.现在,需要注意的一件事是,这将取决于具有相关权限来重命名文件的用户.根据安全性,可能不允许这样做,因此您的应用程序设计必须考虑到这一点.

File.Move [
The FileSystemWatcher has nothing to do with handling changes from a UI. It is intended to monitor changes to a file system (hence it''s name). Your application needs to drive the logic to rename the file - in other words, it needs to perform a File.Move to rename the file from one filename to the other. Now, one thing to be aware of is that this is going to depend on the user having the relevant permissions to rename the file; depending on security, this might not be allowed, so your application design will have to take this into account.

File.Move[^] documentation.


这篇关于在C#.net中使用FilesystemWatcher重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆