How do I delete a directory?

Previous topic - Next topic

ampos

I am using KILLFILE to kill all files inside a directory, but I can not delete the directory...

I am trying SHELLCMD "rd directory" with no luck...

any idea?

MrTAToad

Sure you are in the correct position to remove the directory ?

ampos

Quote from: MrTAToad on 2011-Mar-03
Sure you are in the correct position to remove the directory ?

Yes, I am on my chair, and I sit the most straight I can...

Or do I need to sit on  :shit: to "remove" a directory?

MrTAToad

You should be in the preceding directory :)

Moebius

He meant are you using absolute paths (e.g. "C:\Program Files\...") or relative paths ("Media\...")?

Also, if you get the command working, you can use "rd /S /Q" to remove all files and subfolders without having to use KILLFILE.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

ampos

hehe, I was joking, opf course

I have been trying do delete an empty sir I created in c:, but again, no luck

Code (glbasic) Select
OK=SHELLCMD("cmd rd c:\t",0,0,z)

Marmor

most times is usefull to kill all file in the directory first and the kill the directory itself

MrTAToad

Quotehehe, I was joking, opf course
I know :)

Sure there are no hidden files in there ?

ampos

I just created this "t" dir in c: and I am trying to delete it. It is really empty. Try my example.

Moebius

Try something like this for your command:
Quote"CMD /C rd C:\t /S /Q"

Just stick the "CMD /C" at the front of whatever you're using.  It seems that you need to use the command prompt to execute the 'RD' command...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

MrTAToad

Its possible that CMD isn't being found - if you can, pause the output window and see what it says.

Failing that, use something like :

Code (glbasic) Select

INLINE
}

extern "C" int rmdir(const char *path);

namespace __GLBASIC__ {
ENDINLINE

FUNCTION KILLDIR%:dirName$
INLINE
    return (DGNat) rmdir(dirName.c_Str());
ENDINLINE
ENDFUNCTION


I haven't tested it, but it's the general idea...

Slydog

#11
You could use the system API.
The following is from my library, written in Visual Basic 6, but could be converted to GLBasic like other API calls.

Code (glbasic) Select
' Constants
Private Const FO_DELETE = &H3
Private Const FOF_RECYCLEBIN = &H40
Private Const FOF_SILENT = &H4
Private Const FOF_NOCONFIRMATION = &H10

Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

' Deletes ALL files and folders (including sub files/folders) matching 'path'
Public Sub File_DeleteAll(path As String, Optional use_recycle_bin As Boolean = False)
    // Ensure file exists
    ...
    Dim file_op As SHFILEOPSTRUCT

    file_op.wFunc = FO_DELETE              'We want to delete the file
    file_op.pFrom = path                   'Which file?
    file_op.fFlags = FOF_NOCONFIRMATION    'NO confirmation
    If use_recycle_bin Then file_op.fFlags = file_op.fFlags + FOF_RECYCLEBIN     'Move to recycle bin?
    SHFileOperation file_op                'Call API
End Function

My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

ampos

Quote from: Serpent on 2011-Mar-03
Try something like this for your command:
Quote"CMD /C rd C:\t /S /Q"

Just stick the "CMD /C" at the front of whatever you're using.  It seems that you need to use the command prompt to execute the 'RD' command...

With a second backslash it did work. Enough for me. Thank you all anyway.

Code (glbasic) Select
ok=SHELLCMD("CMD /C rd C:\\t /S /Q",0,0,z)

Kitty Hello

not x-platform, mind.

Why do you need that? I mean - why did you create it in the first place? :P

removing a directory is quite stupid on most platoforms, because you iterate through all subdirs and files and delete these first. Pretty complicated.

ampos

I am making an editor for internal use.

The editor rename files and launch automatically external setbox program, as setbox need directories. So I create a dir, place the file, create the shoebox, delete the file inside the dir and "try to delete the dir"

BTW, loadsprite works with jpeg files, but not if they are inside a shoebox.

Still I have not try jpg on iphone, just in win current version, and it works fine. But as they have to be "protected" in someway, I use a shoebox for each file, so I discover that jpg files inside a shoebox does not work. So I switched back to png, but png files are huge... I would love to use jpg...