How do I delete a directory?

Previous topic - Next topic

Kitty Hello

jpg only "works" on windows it seems. t least on iPhone it crashes dramatically. :(

S.O.P.M.

To dig up an very old thread isn't very welcome but I see a good reason to do it nevertheless. I'd the problem not to be able to delete a folder. Now it works but I really ask myself how about proper path definitions. When can I use "\" and when "/" and is this dependend on the operating system my app is running on? GLBasic returns a path with "/" but on Windows, path levels are seperated by "\". And is it important to have a seperator at the end of a path declaration?

It would be helpful to have basic knowledge about this!
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

MrTAToad

Windows allows / and \

As other systems just use / you might as well stick to using just /

After all, why give yourself extra trouble :)

S.O.P.M.

Ouh okay! Nice to know, thanks. Have decided to use the slash because it has to work on Android also.
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

Kitty Hello

GLBasic always uses forward slash!

Gesendet von meinem GT-N7100 mit Tapatalk


S.O.P.M.

I've found out that I have to use the back slash on Android, otherwise no proper file operation will happen. At least in my case. It's ok for me because this way it works on Windows also and I don't have to use different, platform dependend, program behavior.
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

MrPlow

OK=SHELLCMD("cmd rmdir c:\t >nul",0,0,z)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Kitty Hello

#22
GLBasic native solution:

Code (glbasic) Select


DelTree("C:/Users/gf/Downloads/demo/test", TRUE)
KEYWAIT

FUNCTION DelTree%: folder$, bReallyKill%=FALSE
LOCAL enter$[]
LOCAL files$[]
LOCAL dirs$[]

LOCAL cd$ = GETCURRENTDIR$()
IF NOT SETCURRENTDIR(folder$) THEN RETURN FALSE

DIMPUSH enter$[], folder$

WHILE LEN(enter$[])
LOCAL fld$ = enter$[-1]
DIMDEL enter$[], -1
SETCURRENTDIR(fld$)
LOCAL tmp$[]
LOCAL ntot% = GETFILELIST("*.*", tmp$[])

LOCAL ntotdir% = INTEGER(ntot% / 0x10000)
FOR ndir% = 1 TO ntotdir%
IF tmp$[0]<>"." AND tmp$[0]<>".."
LOCAL full$ = fld$ + "/" + tmp$[0]
DIMPUSH enter$[], full$
DIMPUSH dirs$[], full$
ENDIF
DIMDEL tmp$[], 0 // pop top
NEXT

FOR nfile% = 1 TO MOD(ntot%, 0x10000)
DIMPUSH files$[], fld$ + "/" + tmp$[nfile%-1]
NEXT
WEND

SETCURRENTDIR(cd$) // otherwise the system hold a handle to the directory to remove!

// reverse dirs, delete from long to short pathes
LOCAL revdir$[]
WHILE LEN(dirs$[])
DIMPUSH revdir$[], dirs$[-1]
DIMDEL dirs$[], -1
WEND

FOREACH f$ IN files$[]
IF bReallyKill
KILLFILE f$
ENDIF
NEXT

FOREACH f$ IN revdir$[]
IF bReallyKill
KILLFILE f$
ENDIF
NEXT

IF bReallyKill
KILLFILE folder$
ENDIF

ENDFUNCTION


It's working now.