如何移动文件VB.NET [英] How to move file VB.NET

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

问题描述

我正在制作一个防病毒软件并通过实时扫描对话框显示何时发现病毒,但是当我点击隔离它的suppost将文件移动到文件夹等但是



System.IO.File.Move(Label1.Text,Application.StartupPath&\ Quuarantine \)



不工作,目录确实存在btw没有任何事情发生在file.can任何人帮助我?提前谢谢



我尝试过:



System.IO .File.Move(Label1.Text,Application.StartupPath&\ Quuarantine \)

im making a antivirus and with real time scanning a dialog shows when a virus is found but when i click quarantine its suppost to move the file to a folder ect but

System.IO.File.Move(Label1.Text, Application.StartupPath & "\Quarantine\")

isnt working and the directory does exist btw nothing happens to the file.can anyone help me out? thanks in advance

What I have tried:

System.IO.File.Move(Label1.Text, Application.StartupPath & "\Quarantine\")

推荐答案

移动文件时,需要指定一个整个目标文件名,而不仅仅是一个文件夹。

例如:

When you move a file, you need to specify a whole destination file name, not just a folder.
For example:
File.Move(label1.Text, Path.Combine(quarantinePath, Path.GetFileName(label1.Text)))

总是使用Path.Combine而不是连接 - 它会为你排序尾部反斜杠。



但是...我之所以使用quarantinePath作为变量而不是Application.StartUpPath的原因是因为你不应该尝试写入App程序文件夹 - 在生产中,它将位于Program Files之下,只有在没有Admin的情况下才能读取权限。在防病毒应用程序中,这一点尤其重要,因为您将危险文件移动到Windows 期望 的区域中以查找可执行文件...



而不是那个,使用一个明智的文件夹,或者有很多。这可能会有所帮助:我应该在哪里存储数据? [ ^ ] - 代码都是C#,但这都是非常基本的东西。

Always use Path.Combine instead of concatenation - it sorts out trailing backslashes for you.

But ... the reason I used "quarantinePath" as a variable instead of Application.StartUpPath is because you shouldn't try to write to the App program folder - in production that will be below the "Program Files" which is read only without Admin permissions. In an antivirus app, that is especially important, as you would be moving dangerous files into an area that Windows expects to find executable files in...

Instead of that, use a "sensible" folder, or which there are quite a few. This may help: Where should I store my data?[^] - the code is all C#, but it's all very basic stuff.


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

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