Example of c filename and path handling method

  • 2020-05-27 06:56:26
  • OfStack


string filePath = @"E:\Randy0528\ Chinese directory \JustTest.rar";
            Response.Write(" File path: "+filePath);
            Response.Write("<br/> Change the extension of the path string. <br/>");
            Response.Write(System.IO.Path.ChangeExtension(filePath, "txt"));
            Response.Write("<br/> Returns the directory information for the specified path string. <br/>");
            Response.Write(System.IO.Path.GetDirectoryName(filePath));
            Response.Write("<br/> Returns the extension of the specified path string. <br/>");
            Response.Write(System.IO.Path.GetExtension(filePath));
            Response.Write("<br/> Returns the filename and extension of the specified path string. <br/>");
            Response.Write(System.IO.Path.GetFileName(filePath));
            Response.Write("<br/> Returns the filename of the specified path string without an extension. <br/>");
            Response.Write(System.IO.Path.GetFileNameWithoutExtension(filePath));
            Response.Write("<br/> Gets the root directory information for the specified path. <br/>");
            Response.Write(System.IO.Path.GetPathRoot(filePath));
            Response.Write("<br/> Returns a random folder name or file name. <br/>");
            Response.Write(System.IO.Path.GetRandomFileName());
            Response.Write("<br/> Create only on disk 1 A named zero-byte temporary file and returns the full path to the file. <br/>");
            Response.Write(System.IO.Path.GetTempFileName());
            Response.Write("<br/> Returns the path to the temporary folder on the current system. <br/>");
            Response.Write(System.IO.Path.GetTempPath());
            Response.Write("<br/> Determines whether the path includes the file extension. <br/>");
            Response.Write(System.IO.Path.HasExtension(filePath));
            Response.Write("<br/> To obtain 1 , indicating whether the specified path string contains absolute or relative path information. <br/>");
            Response.Write(System.IO.Path.IsPathRooted(filePath));

File path: E:\Randy0528\ Chinese directory \ JustTest.rar
Change the extension of the path string.
E:\Randy0528\ Chinese directory \ JustTest.txt
Returns the directory information for the specified path string.
E:\Randy0528\ Chinese directory
Returns the extension of the specified path string.
.rar
Returns the filename and extension of the specified path string.
JustTest.rar
Returns the filename of the specified path string without an extension.
JustTest
Gets the root directory information for the specified path.
E:\
Returns a random folder name or file name.
ct2h5b2h.sed
Create a 1-named zero-byte temporary file on disk and return the full path to the file.
C:\Documents and Settings\Randy\Local Settings\Temp\tmpAD.tmp
Returns the path to the temporary folder on the current system.
C:\Documents and Settings\Randy\Local Settings\Temp\
Determines whether the path includes the file extension.
True
Gets a value indicating whether the specified path string contains absolute or relative path information.
True


Related articles: