Reputation: 35
I have the following code that throws an exception "Path not found".
Dim myfso As New FileSystemObject
Set myfso = CreateObject("Scripting.FileSystemObject")
Dim myoFile As Object
Set myoFile = myfso.CreateTextFile("C:\Users\myname\dropbox_folder\Dropbox\dropboxpath.txt")
myoFile.WriteLine "C:\Users\myname\dropbox_folder\Dropbox\"
myoFile.Close
Set myfso = Nothing
Set myoFile = Nothing
Dim strContents As String
Dim myfso1 As New FileSystemObject
Set myfso1 = CreateObject("Scripting.FileSystemObject")
Dim myoFile1 As Object
Dim mypath As String
Set myoFile1 = myfso1.OpenTextFile("C:\Users\myname\dropbox_folder\Dropbox\dropboxpath.txt", ForReading)
strContents = myoFile1.ReadAll
myoFile1.Close
Dim fso, oFolder, oSubfolder, oFile, queue As Collection
Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add fso.GetFolder(strContents)
This last command throws the exception: Path not found. But the path exist "C:\Users\myname\dropbox_folder\Dropbox\" and this is positive lets not argue about that.
The strange is that if you point the mouse over the variable you see this: "C:\Users\myname\dropbox_folder\Dropbox\ without the second ". That is a bit strange for me. Furthermore, if I run the previous command
queue.Add fso.GetFolder("C:\Users\myname\dropbox_folder\Dropbox\")
the code executes smoothly.
What is the problem in your opinion?
Upvotes: 0
Views: 761
Reputation: 175936
Change to:
myoFile.Write "C:\Users\myname\dropbox_folder\Dropbox\"
because WriteLine
appends a VbCrLf
(\r\n
) to the file. When you subsequently ReadAll
you end up with VbCrLf
on the end of the path, invalidating it. (The CrLf is not displayed in the single line tool-tip but manifests as the absent closing "
)
Upvotes: 1