|
Post by tsh73 on Oct 4, 2019 8:48:51 GMT
making sure long path - something along "C:\WRK\sub dir1\subdir2\subdir3" - exists so we can use it.
Tested on JB 2.0, Win 10
'making nested folders (creating folders along long path) 'tsh73 Oct 2019 'works with absolute and relative paths 'returns ' 0 is last folder got created, ' 183 if folder already exisis - but that still means you can use it ' some other error code if something is wrong ' like, [Error 267] The directory name is invalid
path$="C:\WRK\sub dir1\subdir2\subdir3" 'Absolute path. test space in - no problem 'path$="C:\WRK\sub dir1\sub:dir2\subdir3" 'bad path - (:) is not permitted 'path$="subdir1\sub dir 2\subdir3" 'relative path
print "Creating deep folder" print , path$
res = mkDeepDir(path$) select case res case 0 print "created OK" case 183 print "folder already exists - OK anyway" case else print "some error happened, code=";res end select
if (res=0) or (res=183) then run "explorer.exe ";path$ end if
end
function mkDeepDir(path$) 'making nested folders (creating folders along long path) 'works with absolute and relative paths 'returns ' 0 is last folder got created, ' 183 if folder already exisis ' some other error code if something is wrong ' like, [Error 267] The directory name is invalid curPath$="" while 1 i=i+1 item$=word$(path$,i, "\") if item$="" then exit while curPath$=curPath$+word$("\",curPath$<>"") +item$ mkDeepDir = mkdir(curPath$) 'print i, curPath$,mkDeepDir if (mkDeepDir<>0) and (mkDeepDir<>183) then exit function 'some error wend end function
|
|