Training
Module
Work with files and directories in a .NET app - Training
Learn how to use .NET, C#, and System.IO to work with directories, paths, files, and the file system.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The FileSystem object offers a number of useful methods when parsing file paths.
The CombinePath method takes two paths and returns a properly formatted combined path.
The GetParentPath method returns the absolute path of the parent of the provided path.
The GetFileInfo method returns a FileInfo object that can be queried to determine the file's properties, such as its name and path.
Do not make decisions about the contents of the file based on the file name extension. For example, the file Form1.vb may not be a Visual Basic source file.
Use the DirectoryName and Name properties of the FileInfo object to determine a file's name and path. This example determines the name and path and displays them.
Dim testFile As System.IO.FileInfo
testFile = My.Computer.FileSystem.GetFileInfo("C:\TestFolder1\test1.txt")
Dim folderPath As String = testFile.DirectoryName
MsgBox(folderPath)
Dim fileName As String = testFile.Name
MsgBox(fileName)
Use the CombinePath
method, supplying the directory and name. This example takes the strings folderPath
and fileName
created in the previous example, combines them, and displays the result.
Dim fullPath As String
fullPath = My.Computer.FileSystem.CombinePath(folderPath, fileName)
MsgBox(fullPath)
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
Work with files and directories in a .NET app - Training
Learn how to use .NET, C#, and System.IO to work with directories, paths, files, and the file system.