34,333
edits
Changes
→Extracting Parts of a Path Name in Visual Basic
== Extracting Parts of a Path Name in Visual Basic ==
<pre>
Dim fileName As String = tmpFile.Name ' hget just the Filename part of the full pathname
MsgBox(fileName) ' Display it
</pre>
== Copying Directories in Visual Basic ==
A directory and all of the files therein may be copied to a new folder using the ''CopyDirectory()'' method:
<pre>
My.Computer.FileSystem.CopyDirectory("C:\Temp", "C:\Temp2", True)
</pre>
The ''True'' parameter tell Visual Basic to overwrite the target directory if it already exists. Setting this to ''False'' will prevent existing directories from being overwritten and instead, the contents of the two directories will be merged.
== Renaming a Directory in Visual Basic ==
To rename a directory using Visual Basic:
<pre>
My.Computer.FileSystem.MoveDirectory("C:\Temp", "C:\Temp2")
</pre>
The following code excerpt will overwrite the target directory if it already exists:
<pre>
My.Computer.FileSystem.MoveDirectory("C:\Temp", "C:\Temp2", True)
</pre>