[Implemented] DeleteDirectory() or RemoveDirectory()
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
[Implemented] DeleteDirectory() or RemoveDirectory()
Restored from previous forum. Originally posted by Ralf.
Hello would be great if there would be a statement or funktion
which delete a directory and it subdirectories.
cOUld be called DeleteDirectory() or RemoveDirectory() or
something like that.
I wrote a Routine to ge rid of all the files in the Directory
und it's subdirectories. But the Directories are still there.
Only the files are deleted.
Hello would be great if there would be a statement or funktion
which delete a directory and it subdirectories.
cOUld be called DeleteDirectory() or RemoveDirectory() or
something like that.
I wrote a Routine to ge rid of all the files in the Directory
und it's subdirectories. But the Directories are still there.
Only the files are deleted.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
PB - Registered PureBasic Coder
In Windows, you can use this command to remove an empty directory:I wrote a Routine to ge rid of all the files in the Directory
und it's subdirectories. But the Directories are still there.
Only the files are deleted.
Code: Select all
dir$="c:\DirToRemove\"
RemoveDirectory_(dir$)
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
(1) dir$="C:\DirToRemove"
(2) RomoveDirectory_(dir$)
Works for me... did you have a trailing slash for (1) above?
(Although I don't think it actually makes a difference...).
And for (2), I assume that Romove was just a typo?
It won't work as a DLL, so test it as an EXE. (Note to Fred: If you add
a "delete dir" command, please ensure it works for EXEs and DLLs).
PB - Registered PureBasic Coder
Edited by - PB on 29 January 2002 14:16:46
(1) dir$="C:\DirToRemove"
(2) RomoveDirectory_(dir$)
Works for me... did you have a trailing slash for (1) above?
(Although I don't think it actually makes a difference...).
And for (2), I assume that Romove was just a typo?
It won't work as a DLL, so test it as an EXE. (Note to Fred: If you add
a "delete dir" command, please ensure it works for EXEs and DLLs).
PB - Registered PureBasic Coder
Edited by - PB on 29 January 2002 14:16:46
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> All commands work with DLL. Why this one shouldn't ?
Don't know, but if I compile+run the code I posted above, while still in the
editor and not as a compiled DLL, it doesn't work. (When the compiler option
is set to Shared DLL, that is). Maybe it works when actually compiled to a
real DLL file, but I haven't tested that... so I apologize if it does work
when done that way.
Don't know why Ralf is having trouble with it though...
PB - Registered PureBasic Coder
> All commands work with DLL. Why this one shouldn't ?
Don't know, but if I compile+run the code I posted above, while still in the
editor and not as a compiled DLL, it doesn't work. (When the compiler option
is set to Shared DLL, that is). Maybe it works when actually compiled to a
real DLL file, but I haven't tested that... so I apologize if it does work
when done that way.
Don't know why Ralf is having trouble with it though...
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Stan.
C with strings like "\thedirectory" or "\newdirectory" as \t and \n are special
sequences, solved it in C with "\\thedirectory" or "\\newdirectory"
Hope this helps.
Learning and Love are what life is all about ...
As a newbie I may be completely off, but I remeber having the same problem in
Don't know why Ralf is having trouble with it though...
PB - Registered PureBasic Coder
C with strings like "\thedirectory" or "\newdirectory" as \t and \n are special
sequences, solved it in C with "\\thedirectory" or "\\newdirectory"
Hope this helps.
Learning and Love are what life is all about ...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Ralf.
This is the Procedure:
OpenConsole()
Procedure DelDirectory(DelDirectory$, Start)
If ExamineDirectory(Start, DelDirectory$, "*.*")
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."
c$ = DelDirectory$+DirectoryEntryName()+"\"
DelDirectory(c$, Start+1)
UseDirectory(Start)
EndIf
Else
If Type = 1
DeleteFile(DelDirectory$+DirectoryEntryName())
EndIf
EndIf
Until Type=0
EndIf
EndProcedure
DelDirectory("C:\DOS99\",Start)
dir$="C:\DOS99"
RemoveDirectory_(dir$)
So what's the problem ? Doesn't work.
Maybe i wait until Fred has implemented the funktion.
Edited by - ralf on 30 January 2002 12:54:03
This is the Procedure:
OpenConsole()
Procedure DelDirectory(DelDirectory$, Start)
If ExamineDirectory(Start, DelDirectory$, "*.*")
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."
c$ = DelDirectory$+DirectoryEntryName()+"\"
DelDirectory(c$, Start+1)
UseDirectory(Start)
EndIf
Else
If Type = 1
DeleteFile(DelDirectory$+DirectoryEntryName())
EndIf
EndIf
Until Type=0
EndIf
EndProcedure
DelDirectory("C:\DOS99\",Start)
dir$="C:\DOS99"
RemoveDirectory_(dir$)
So what's the problem ? Doesn't work.
Maybe i wait until Fred has implemented the funktion.
Edited by - ralf on 30 January 2002 12:54:03
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> dir$="C:\DOS99"
> RemoveDirectory_(dir$)
The above code works for me with both Win 95 and Win 2000...
Are you 100% certain that the directory is empty? Probably a stupid question,
I guess, but still... are there no hidden files or anything?
PB - Registered PureBasic Coder
Edited by - PB on 30 January 2002 13:18:15
> dir$="C:\DOS99"
> RemoveDirectory_(dir$)
The above code works for me with both Win 95 and Win 2000...
Are you 100% certain that the directory is empty? Probably a stupid question,
I guess, but still... are there no hidden files or anything?
PB - Registered PureBasic Coder
Edited by - PB on 30 January 2002 13:18:15
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> It's empty except there are empty subdirectories.
Ah, that's why! The directory to be removed has to be empty, as I said
at the start. It cannot contain anything else inside it, not even other
empty directories.
PB - Registered PureBasic Coder
> It's empty except there are empty subdirectories.
Ah, that's why! The directory to be removed has to be empty, as I said
at the start. It cannot contain anything else inside it, not even other
empty directories.
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> aha . that 's the reason.
Yep. So modify your procedure a bit to remove the emptied directories as soon
as all the files have been deleted in each one, and it'll work just fine.
> This RemoveDirectory_(dir$), where is it from ?
It's a Win32 API command which is built-in to all Windows versions.
PB - Registered PureBasic Coder
Edited by - PB on 30 January 2002 14:15:14
> aha . that 's the reason.
Yep. So modify your procedure a bit to remove the emptied directories as soon
as all the files have been deleted in each one, and it'll work just fine.
> This RemoveDirectory_(dir$), where is it from ?
It's a Win32 API command which is built-in to all Windows versions.
PB - Registered PureBasic Coder
Edited by - PB on 30 January 2002 14:15:14