Path静态类

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 文件IO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void butFile_Click(object sender, EventArgs e)
        {   
            //更改路径字符串的后缀名,不会改变实际路径
            string newPath = Path.ChangeExtension(@"D:\1.txt", "avi");
            //合并多个字符路径如果没有\自动加
            newPath = Path.Combine(@"12.txt", "12.txt");
            string path = @"G:\BaiduYunDownload\update.bin";
            //得到文件路径所在目录,如果本身就是目录路径则直接返回
            //只是操作字符串,不会去寻找文件
            newPath = Path.GetDirectoryName(path);
            //得到指定路径的文件名,如果不是文件路径,返回空串
            newPath = Path.GetExtension(path);
            //得到路径的文件名(文件名是带扩展名的)
            newPath = Path.GetFileName(path);
            //得到没有后缀名的文件名
            newPath = Path.GetFileNameWithoutExtension(path);
            //由文件在程序的相对路径得到文件的绝对物理路径
            newPath = Path.GetFullPath(path );
            //得到系统的临时目录,使用完由系统清除
            newPath = Path.GetTempPath();
            //产生一个随机的系统temp文件,返回文件名;
            newPath = Path.GetTempFileName();

        }
    }
}

 

posted on 2014-06-18 19:46  404 NotFound!  阅读(112)  评论(0编辑  收藏  举报

导航