[RESOLVED] problem with mkdir command!
Cant find out why this doesnt work!
The following works...
Code:
'CREATE FOLDERS TO STORE THE DOWNLOADED FILES
Private Sub createfolders()
MkDir "c:\config\audio"
MsgBox "folders done"
End Sub
But this wont!
(The folders.dat file contains ) The msgbox displays the correct path, so it is reading it correctly. I get a 'Runtime Error 76: Path not found' error...
Code:
'CREATE FOLDERS TO STORE THE DOWNLOADED FILES
Private Sub createfolders()
Open "C:\config\folders.dat" For Input As #1
Input #1, data
path = data
MkDir path
MsgBox (path)
Close #1
MsgBox "folders done"
End Sub
Thyanks
Re: problem with mkdir command!
I'm not sure what 'data' contains. MKDir cannot create more than one subfolder at a time.
If you had C:\1\2\3\4 as a path, in order to create \4, C:\1\2\3 would have to exist or be created first. So using MKDir, you want to split your path into separate subfolders and then ensure each subfolder exists and if not, then create that subfolder, one at a time.
Also, MKDir will fail/error if the path already exists.
Re: problem with mkdir command!
If your hardcoded code works then Try
MkDir Trim(path)
Probably some leading or trailing spaces are creating the problem...
Also if you run the hardcoded code first then remember to delete the destination path before trying the softcoded code...
Re: problem with mkdir command!
The SHCreateDirectoryEx API can make multiple sub folders in one call and won't error if the folder already exists, might want to try something like this,
Code:
Option Explicit
'SHCreateDirectoryEx - Minimum operating systems: Windows 2000, Windows Millennium Edition
Private Declare Function SHCreateDirectoryEx Lib "shell32" Alias "SHCreateDirectoryExA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal psa As Any) As Long
Private Sub createfolders()
Dim sPath As String
Open "C:\config\folders.dat" For Input As #1
Do Until EOF(1)
Line Input #1, sPath
sPath = Trim$(sPath)
If Len(sPath) > 0 Then SHCreateDirectoryEx Me.hwnd, sPath, ByVal 0&
Loop
Close #1
End Sub
Re: problem with mkdir command!
Lavolpe,
Thanks but it 'does' work when hardcoded, so that is not the issue (i dont think). Also yes, I have an error capture for existing directories, which I am ignoring for the tme being. Thanks
Koolsid, still gives error with the 'trim'... Am goign to try edgemeals suggestion.
thanks for your time.
Re: problem with mkdir command!
edgemeal, works a treat, thanks!
Re: [RESOLVED] problem with mkdir command!
Great it is sorted...
But out of curiosity, can you check what is the value of path at the time of error..
vb Code:
path = data
msgbox path
MkDir path
Re: [RESOLVED] problem with mkdir command!
the strange thing is, thats why i put that there, and the value of path is correct! :-|
strange
Re: [RESOLVED] problem with mkdir command!
It isn't strange. I think that c:\config did not exist on the hard drive.
Therefore MKDir c:\config\audio returns path not found because it can't create the audio subfolder without the config folder first being created.
Substitute c:\config\audio with whatever was actually read into the Data/Path variable.
Just a matter of understanding the MKDir requirements and limitations.
Re: [RESOLVED] problem with mkdir command!
but it worked hard coded?
Re: [RESOLVED] problem with mkdir command!
It worked hardcoded because c:\config was already there.
Proof: Try this, hardcoded:
MKDir "C:\RootBogus_123\SubBogus_123"
Path not found error will occur, because RootBogus_123 does not exist.