如何将txt文件移动到其他文件夹 [英] how to move txt file to other folder

查看:295
本文介绍了如何将txt文件移动到其他文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试编写一个控制台应用程序C#将txt文件移动到其他文件夹
该功能只是将某些.txt文件从文件夹A复制到文件夹AA

字符串来源="C:\\ A \\ ResultClassA.txt";
File.Move(Source,"C:\\ AA");

但始终提示错误消息:

拒绝访问该路径.

故障排除提示:
确保您具有访问此资源的足够特权.
如果您尝试访问文件,请确保该文件不是ReadOnly.
获取此异常的一般帮助.

在执行"File.move"代码之前,我真的需要将文件夹A和文件夹B设置为不只读"属性吗?并设置为仅在成功移动后回读?

有什么主意吗?

谢谢.
通过Hero

Hi,

I try to write a console app C# to move my txt files to other folder
The functions is just copy certain .txt files from folder A to folder AA

string source = "C:\\A\\ResultClassA.txt";
File.Move(Source, "C:\\AA");

but its alway prompt error message:

Access to the path is denied.

Troubleshooting tips:
Make sure you have sufficient privileges to access this resource.
If you are attempting to access a file, make sure it is not ReadOnly.
Get general help for this exception.

Do i really need to set my folder A and folder B to "NOT ReadOnly" attribute before "File.move" code are execuse? and set to read only back after success moved?

any idea?

Thanks.
By Hero

推荐答案

不,那要复杂得多.在Vista及更高版本中受保护的根目录可防止普通用户在其中写入-您需要具有管理员权限.
由于您的目的地是"C:\ AA",因此它试图在根目录中创建一个名为"AA"的文件. ( MSDN [
No, it''s more complex that that. The root directory in protected in Vista and above to prevent normal users writing in it - you need admin privileges.
Since your destination is "C:\AA" it is trying to create a file called "AA" in the root directory. (MSDN[^])
Try writing it to a different folder and it will work, otherwise you will need to elevate your privilege level.
Or if "AA" is a folder, try "C:\AA\ResukltClassA.txt" instead.


错误消息提示,访问被拒绝.

确保目标路径存在,并且可以通过资源管理器访问它.
As the error message suggests, access is denied.

Make sure the target path exists and that you can access it via explorer.


这篇关于如何将txt文件移动到其他文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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