ASP.NET修改文件夹名称

directory 提供静态方法。

directoryinfo 实例提供实例方法;

ContractedBlock.gif ExpandedBlockStart.gif 修改文件夹名称代码
 
   
string srcFileName = @" D:\a.txt " ;
string destFileName = @" D:\b.txt " ;

string srcFolderPath = @" D:\1 " ;
string destFolderPath = @" D:\6 " ;

// 方法一
if (System.IO.File.Exists(srcFileName))
{
System.IO.File.Move(srcFileName, destFileName);
}
if (System.IO.Directory.Exists(srcFolderPath))
{
System.IO.Directory.Move(srcFolderPath, destFolderPath);
}

// 方法二
if (System.IO.File.Exists(srcFileName))
{
System.IO.FileInfo file
= new System.IO.FileInfo(srcFileName);
file.MoveTo(destFileName);
}
if (System.IO.Directory.Exists(srcFolderPath))
{
System.IO.DirectoryInfo folder
= new System.IO.DirectoryInfo(srcFolderPath);
folder.MoveTo(destFolderPath);
}

方法三:

FSO实现,不用移动内部文件。

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
// C#动态修改文件夹名称(FSO实现,不移动文件)
string lstrFileFolder = HttpContext.Current.Server.MapPath(Com.Common.m_folderData);
string subFolder = System.DateTime.Today.AddDays( - 1 ).ToString( " yyMMdd " );
string newFolder = System.DateTime.Today.ToString( " yyMMdd " );
string path = lstrFileFolder + subFolder;
// 判断目录是否存在,存在则改名
if (Directory.Exists(path))
{
Scripting.FileSystemObject fso
= new Scripting.FileSystemObjectClass();
fso.GetFolder(path).Name
= newFolder;
}System.IO.Directory.Move(
" 源目录 " , " 新目录 " );
OR

项目-
> 引用 浏览 COM组件 Microsoft Scripting Runtime ,
Scripting.FileSystemObject fso
= new Scripting.FileSystemObjectClass();
fso.GetFolder(
" 目录 " ).Name = " 新目录名 " ;

 

 

 

 

转载于:https://www.cnblogs.com/netact/articles/1788506.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值