如何将文件从一个路径移动到另一个路径? [英] how to move file from one path to another ?
本文介绍了如何将文件从一个路径移动到另一个路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我写的代码,但它不起作用。请看看
string destination = Path.Combine(
DataFeed.CaremarkInbound.Locations.CaremarkInboundArchive, new DirectoryInfo(
file.CurrentFilePath).Name);
Directory.Move(file.CurrentFilePath,destination);
获得例外
当该文件已存在时,无法创建文件
提前谢谢
解决方案
错误是不言自明的?在您进行移动之前,请使用File.Exists查看目标文件是否存在,以及是否删除它
http://www.dotnetperls.com/file-exists [ ^ ]
http://www.dotnetperls.com/file-delete [ ^ ]
here is the code i have written but it is not working. please have a look
string destination = Path.Combine(
DataFeed.CaremarkInbound.Locations.CaremarkInboundArchive, new DirectoryInfo(
file.CurrentFilePath).Name);
Directory.Move(file.CurrentFilePath, destination);
getting the exception as
Cannot create a file when that file already exists
Thanks in advance
解决方案
The error is self-explanatory? Before you do the move use File.Exists to see if the destination file exists, and if it does delete it
http://www.dotnetperls.com/file-exists[^]
http://www.dotnetperls.com/file-delete[^]
这篇关于如何将文件从一个路径移动到另一个路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文