文件删除问题

lyrzhlgq 2003-09-29 12:48:13
我在程序中需要删除某个路径下的文件,是这样写的
System.IO.File.Delete("manage\SysDocument\first.doc")
调试时告诉我文件的路径字符串过长,执行出现异常,
我该怎么解决这个问题
...全文
30 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyrzhlgq 2003-09-29
  • 打赏
  • 举报
回复
又出现问题了
myfile.exist(filepath);中filepath="manage\SysDocument\first.doc"
在执行时,该语句为myfile.exist(c:\window\System32\manage\SysDocument\first.doc)
而我的文件的实际路径为d:\file\manage\SysDocument\first.doc
所以执行结果为false ,
当我改为myfile.exist(System.IO.Directory.GetCurrentDirectory()+filepath)时得到的当前路径为c:/window\System,没能实现我想要得结果
lyrzhlgq 2003-09-29
  • 打赏
  • 举报
回复
问题ok了
cdbnzc 2003-09-29
  • 打赏
  • 举报
回复
加了@还是不可以么?
不懂艾
lxhong1980 2003-09-29
  • 打赏
  • 举报
回复
学习
9742wsx 2003-09-29
  • 打赏
  • 举报
回复
FileInfo myfile = new FileInfo(filepath);
if (myfile.Exists)
{
myfile.Delete();
}
lyrzhlgq 2003-09-29
  • 打赏
  • 举报
回复
大熊的方法我试了,还是不行
lyrzhlgq 2003-09-29
  • 打赏
  • 举报
回复
实际上我的代码为
string filepath=sd.url;//sd.url为从数据库某表的一个字段中取出来得
System.IO.File.Delete(filepath);
davixiong 2003-09-29
  • 打赏
  • 举报
回复
你的文件路径不对,应该类似于这样的

System.IO.File.Delete(System.IO.Directory.GetCurrentDirectory() + @"\manage\SysDocument\first.doc")

lyrixliu 2003-09-29
  • 打赏
  • 举报
回复
如果C#的话是应该用\\符号的
lyrzhlgq 2003-09-29
  • 打赏
  • 举报
回复
引号中的路径是我给的一个例子,只是用来说明路经过长,我该怎么解决这个问题呢
lyrixliu 2003-09-29
  • 打赏
  • 举报
回复
看看
System.IO.File.Delete("manage\SysDoc~1\first.doc")
如何?


PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
PlayIrrrr 2003-09-29
  • 打赏
  • 举报
回复
System.IO.File.Delete("manage\\SysDocument\\first.doc")

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧