需要 using System.IO;

1) 相对路径转绝对路径
string fullfolder = HttpContext.Current.Server.MapPath(folder);

2) 文件移动(改名)
File.Move(Server.MapPath("/a.txt"), Server.MapPath("/b.txt"));

3) 文件复制
File.Copy(Server.MapPath("/a.txt"), Server.MapPath("/b.txt"), true);

4) 文件是否存在
File.Exists(filefullname)

5) 目录是否存在
Directory.Exists(fullfolder))

6) 创建目录
Directory.CreateDirectory(fullfolder);

7) 目录移动
Directory.Move

8) 读取文本文件
StreamReader srd = File.OpenText(fullfilename);
srd.ReadToEnd();
srd.Close();
srd.Dispose();

9) 写文件
StreamWriter swr = File.CreateText(Server.MapPath("test.txt"));
swr.Write("message");
swr.Close();
swr.Dispose();

10)删除文件
// 删除硬盘上的文件
if (File.Exists(filefullname))
{
File.Delete(filefullname);
}

11)目录遍历
public void ListFiles(string pathname)
{
// 所有目录与文件
string[] subDirs = Directory.GetDirectories(pathname);
string[] subFiles = Directory.GetFiles(pathname);

foreach (string subDir in subDirs)
{
ListFiles(subDir);
}

// 所有文件
foreach (string subFile in subFiles)
{
string filename = Path.GetFileName(subFile);
}
}

12)文件修改时间
FileInfo fi = new FileInfo(@"c:\test.txt");
DateTime writetime = fi.LastWriteTime;

13)从含路径的文件名中提取文件名
System.IO.Path.GetFileName(fullPath);//文件名

C#文件目录操作完全手册的更多相关文章

  1. paip.文件目录操作uAPI php python java对照

    paip.文件目录操作uAPI php python java对照 chdir -- 改变目录 chroot -- 改变根目录 dir -- directory 类 closedir -- 关闭目录句 ...

  2. php文件夹与文件目录操作函数

    在php中一些常用的文件夹/文件目录操作函数总结. php文件夹操作函数 string basename ( string path [, string suffix] ) 给出一个包含有指向一个文件 ...

  3. 你一定要知道的关于Linux文件目录操作的12个常用命令

    写在前面: 1,<你一定要知道的关于Linux文件目录操作的12个常用命令>是楼主收集的关于Linux文件目录操作最常用的命令,包括文件或目录的新建.拷贝.移动.删除.查看等,是开发人员操 ...

  4. [PY3]——IO——文件目录操作

    IO—os.shutil—文件目录操作 目录操作 1. 新建 os.mkdir(path[, mode]) 相当于mkdir,新建目录 os.makedirs(path[, mode]) 相当于mkd ...

  5. python OS 模块 文件目录操作

    Python OS 模块 文件目录操作 os模块中包含了一系列文件操作的函数,这里介绍的是一些在Linux平台上应用的文件操作函数.由于Linux是C写的,低层的libc库和系统调用的接口都是C AP ...

  6. php 文件夹 与 文件目录操作

    php文件夹操作函数 string basename ( string path [, string suffix] )给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名.如果文件名是 ...

  7. Vim 中进行文件目录操作

    Vim 中进行文件目录操作 当前文件名 我们知道Vim有48个寄存器,其中%只读寄存器中保存着当前文件路径. 例如在/home/harttle/下打开src/main.cpp,我们打印%的值: :ec ...

  8. python2.7.13标准库文件目录操作与文件操作

    标准库的中文参考文档: http://python.usyiyi.cn/translate/python_278/library/index.html 官方标准库文档:https://docs.pyt ...

  9. php操作mongodb手册地址

    php操作mongodb手册地址: http://php.net/manual/zh/class.mongocollection.php

随机推荐

  1. ASP.NET Core 中文文档 第二章 指南(3)用 Visual Studio 发布一个 Azure 云 Web 应用程序

    原文:Getting Started 作者:Rick Anderson 翻译:谢炀(Kiler) 校对:孟帅洋(书缘).刘怡(AlexLEWIS).何镇汐 设置开发环境 安装最新版本的 Azure S ...

  2. ASP.NET Core 中文文档 第三章 原理(17)为你的服务器选择合适版本的.NET框架

    原文:Choosing the Right .NET For You on the Server 作者:Daniel Roth 翻译:王健 校对:谢炀(Kiler).何镇汐.许登洋(Seay).孟帅洋 ...

  3. [原创]django+ldap+memcache实现单点登录+统一认证

    前言 由于公司内部的系统越来越多,为了方便用户使用,通过django进行了单点登录和统一认证的尝试,目前实现了django项目的单点登录和非django项目的统一认证,中间波折挺多,涉及的技术包括dj ...

  4. Basic Tutorials of Redis(2) - String

    This post is mainly about how to use the commands to handle the Strings of Redis.And I will show you ...

  5. Ionic2系列——使用DeepLinker实现指定页面URL

    Ionic2使用了近似原生App的页面导航方式,并不支持Angular2的路由.这种方式在开发本地App的时候比较方便,但如果要用来开发纯Web页面就有点问题了,这种情况下Angular2的route ...

  6. csharp: Download SVN source

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. JavaWeb_day07_JSP

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! day07 JSP 全称 :Java Server P ...

  8. servlet开发中遇到的问题集合

    问题1: servlet插入数据库时中文会乱码. 解决方法:在数据库连接地址最后增加两个转码参数(?useUnicode=true&characterEncoding=utf8) url=jd ...

  9. 关于fefo函数

    feof是C语言标准库函数函数,其原型在stdio.h中,其功能是检测流上的文件结束符. 函数原型: int feof(FILE *stream); 返回值:如果文件结束,则返回非0值,否则返回0 在 ...

  10. PDO运用