Path

In this chapter you will learn:

  1. Path operation

Path operation

The static Path class defines methods and fields for working with paths and filenames.

using System;//from j a  v a 2 s.co  m
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        string dir = @"c:\g";
        string file = "myfile.txt";
        string path = @"c:\g\myfile.txt";

        Directory.SetCurrentDirectory(@"k:\demo");
        Directory.GetCurrentDirectory();
        Path.IsPathRooted(file);
        Path.IsPathRooted(path);
        Path.GetPathRoot(path);
        Path.GetDirectoryName(path);
        Path.GetFileName(path);
        Path.GetFullPath(file);
        Path.Combine(dir, file);
        Console.WriteLine(Path.GetTempFileName());
        Console.WriteLine(Path.GetTempPath());
    }
}

Next chapter...

What you will learn in the next chapter:

  1. Use DirectoryInfo to create sub directory
Home » C# Tutorial » File, Path
File creation
Deleting Files
Put to recycle bin
File Exists
File moving
File size
File attribute
Set file attribute
File time change
File time
Random file name
Temporary file
Path
Directory creation
Delete directory
Path existance
Change the path
Current Path
Directory listing
Recursive Path Listing
Combine path
Calculate Directory Size
Invalid path characters
System path
Directory copy
Drive
Drive information
File access rule
File System watcher