This is the code I have set up to scan a directory of files:
Dim fileArray() As String
fileArray = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory & "help\")
And it successfully gets all files in the directory, but it gets their absolute paths aswell. For example, one of the entries in fileArray()
is:
F:\Project\Project\bin\x86\Debug\help\book_troubleshoot.html
And I want it to just be:
book_troubleshoot.html
Is there a way to do this without parsing through all the array entries to trim off the path?
Thanks.
Normally find command will retrieve the filename and its path as one string. If you want to display only the filename, you can use basename command. find infa/bdm/server/source/path -type f -iname "source_fname_*. txt"
GetFiles. This returns the file names in a folder. It returns a string array—this contains the full paths of all the files contained inside the specified directory.
Paths include the root, the filename, or both. That is, paths can be formed by adding either the root, filename, or both, to a directory.
Use the substring() method to get the filename without the path, e.g. fullPath. substring(fullPath. lastIndexOf('/') + 1) . The substring method will return a new string containing only the characters after the last slash.
string filename= System.IO.Path.GetFileName(fullpathname);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With