You surely have experienced problems in creating a folder if you've made some code for the file system. In win32 if you have C:\folder1 you cannot create the file C:\folder1\my_proggie\bin\data.dat without building the whole path, which is hell of impleasant work. Here I've put two functions: BuildPath does everything by itself, and even detects if it is relative ("folder1\folder2") or global path ("C:\folder1\folder2") to be correct anyway. BuildPath2 is the same with the difference that it thinks you've specified a filename, and it has to make all its parent directories, then you easily create the new file.



;=====[[ BUILD PATH >>===\
BuildPath proc uses ebx ecx edx Path
local DaDir[260]:BYTE
local StartPos
mov eax,Path
mov al,[eax+1]
.if al==":"
mov StartPos,4
.else
mov StartPos,1
.endif
_mremore:
invoke lstrcpy,addr DaDir,Path
invoke InString,StartPos,addr DaDir,CTEXT("\")
.if eax>0 && eax<260
push eax
lea ebx,DaDir
mov byte ptr[ebx+eax],0
invoke GetFileAttributes,addr DaDir
.if eax==-1
invoke CreateDirectory,addr DaDir,0
.if !eax
jmp _all_done
.endif
.endif
pop eax
inc eax
mov StartPos,eax
jmp _mremore
.elseif eax==0
invoke GetFileAttributes,addr DaDir
.if eax==-1
invoke CreateDirectory,Path,0
jmp _all_done
.else
mov eax,1
jmp _all_done
.endif
.endif
_all_done:
ret
BuildPath endp

; BuildPath2 is the same, with the exception that it does not
; build the last folder, thinks it's a filename!
BuildPath2 proc uses ebx ecx edx Path
local DaDir[260]:BYTE
local StartPos
mov eax,Path
mov al,[eax+1]
.if al==":"
mov StartPos,4
.else
mov StartPos,1
.endif
_mremore:
invoke lstrcpy,addr DaDir,Path
invoke InString,StartPos,addr DaDir,CTEXT("\")
.if eax>0 && eax<260
push eax
lea ebx,DaDir
mov byte ptr[ebx+eax],0
invoke GetFileAttributes,addr DaDir
.if eax==-1
invoke CreateDirectory,addr DaDir,0
.if !eax
jmp _all_done
.endif
.endif
pop eax
inc eax
mov StartPos,eax
jmp _mremore
.elseif eax==0
mov eax,1
jmp _all_done
.endif
_all_done:
ret
BuildPath2 endp
;=======/


Posted on 2002-11-18 21:11:45 by Ultrano
:alright:

Now add support for network paths. ( \\servername\sharename\folder1\folder2 ) ;)
Posted on 2002-11-18 22:06:22 by iblis
lol
yeah , sure :)

why not upgrade it to make concrete paths, too?
Posted on 2002-11-19 00:37:31 by Ultrano

why not upgrade it to make concrete paths, too?
Is a 'concrete path' also known as a sidewalk? :grin:
Posted on 2002-11-19 07:14:20 by bitRAKE
yeah, but if I wrote it like that, no-one would find the connection and meaning!
btw, I figured out how the function to build sidewalks, and I am currently making the hardware to it - put my computer on wheels, got four robotic arms attached to it, and two LEDs for eyes. My computer looks very angry now, and I think it wants a revenge for all those fists it ate when it didn't work properly. I broke its CD-ROM, but I don't wanna know what it's gonna break about me....
Got to go ... I think it invoked the revenge function.........

....... SOS msg .... got to .... press ENTER .....
Posted on 2002-11-21 22:02:06 by Ultrano
gusto, no neprotivokonstitucionstvuvatelstvuvai...
Posted on 2002-11-22 11:44:38 by lingo12
:grin:

chichkovite chervenotikvenichkovcheta ve, majna
:) (bg). In what language is the second word you wrote? In Bulgarian in must be changed to "ne", in order to mean what it meant to be :)

dosvidanje
Posted on 2002-11-22 20:44:33 by Ultrano
"In what language is the second word you wrote?"

ono e "ne" be sersem, kaza vela, deka e debela i ia i vikam oti a ona se kikoti..
sedni si na poslednia chlen na otdelitelnata sistema i si opravi nastroikite...Vervai mi!
I'm a linguist he..he
Posted on 2002-11-22 21:45:58 by lingo12