I have the following code.
Dim text As String = IO.File.ReadAllText("C:\Example.xtp")
This code is specific to a single file, however I would like to file.readalltext
for every file in a particular directory.
How can I achieve this?
To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null.
GetFiles(String, String, SearchOption) Returns the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.
In Visual Studio, click File > Open > Folder. Navigate to the folder, and click Select Folder. This opens the folder in Solution Explorer and displays its contents, files and any subfolders.
Open your project in Visual Studio > click the Show All Files button > expand the bin , Debug > select and right-click the parent folder > choose Include in Project option.
You will need to use the IO.Directory.GetFiles function.
Dim files() As String = IO.Directory.GetFiles("c:\")
For Each file As String In files
' Do work, example
Dim text As String = IO.File.ReadAllText(file)
Next
Dim fileEntries As String() = Directory.GetFiles("YourPath", "*.txt")
' Process the list of .txt files found in the directory. '
Dim fileName As String
For Each fileName In fileEntries
If (System.IO.File.Exists(fileName)) Then
'Read File and Print Result if its true
ReadFile(fileName)
End If
TransfereFile(fileName, 1)
Next
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