Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » deleting directory

This thread is locked; no one can reply to it. rss feed Print
deleting directory
William Labbett
Member #4,486
March 2004
avatar

hi guys,

is there a way to delete a directory and all it's contents with A5 ?

Thanks.

verthex
Member #11,340
September 2009
avatar

If you could somehow invoke dos commands from A5 sure.

SiegeLord
Member #7,827
October 2006
avatar

Yes, by recursively looking through a directory using al_open_directory /al_read_directory (using al_get_fs_entry_mode to tell if the current entry is a directory and needs to be recursed into) and then using al_remove_fs_entry to actually delete the file/empty directory.

There's obviously no convenience function for that, but doing the above shouldn't take more than 10-20 lines.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

William Labbett
Member #4,486
March 2004
avatar

Thanks.

Maybe it'd be easier to do with a scipt ?

I'm using a script to compile and run my program.

I've tried using the rmdir command but it says command not found, even though it's in the bash docs.

SiegeLord
Member #7,827
October 2006
avatar

Well, in that case you'd use rm:

rm -rf directory_name

Be careful with what you put in the directory_name lest you delete something you didn't want to delete.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

William Labbett
Member #4,486
March 2004
avatar

Thanks. Still getting a command not found.

#!bin/bash
rm -rf "C:\pongping8\feature_hits_circle_dir_01" 

cd C:/pongping8
if mingw32-make 
then 
./pong_game.exe 
fi
read -p "press a key"

C:\pongping8\make_pongping.sh: line 2: rm: command not found
mingw32-make: `pong_game.exe' is up to date.
Press any key to continue . . .

SiegeLord
Member #7,827
October 2006
avatar

You're using bash... on Windows? That's surprising.

You'll need to find the Windows equivalent then, I guess. ???

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

William Labbett
Member #4,486
March 2004
avatar

On Windows, MSYS can be used to use the bash commands. Although I only get this when I call it from MSYS :

william@william-PC ~
$ cd C:/pongping8

william@william-PC /c/pongping8
$ ./make_pongping.sh
sh: ./make_pongping.sh: bin/sh^M: bad interpreter: No such file or directory

william@william-PC /c/pongping8
$

J-Gamer
Member #12,491
January 2011
avatar

Shouldn't that be /bin/sh?

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

William Labbett
Member #4,486
March 2004
avatar

I don't know. I changed it to that to see if it would work. I've changed it back and I still get the same output.
I've never know wht that line does.

J-Gamer
Member #12,491
January 2011
avatar

It tells the system that the program should be opened with bin/sh. As it seems it is already being opened with sh, try removing the line.(I'm just guessing here)

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

William Labbett
Member #4,486
March 2004
avatar

Okay, I tried that but I still get this :

C:\pongping8\make_pongping.sh: line 2: rm: command not found
mingw32-make: `pong_game.exe' is up to date.
Press any key to continue . . .

Haven't got a clue why it's not found.

I must be doing something stupid.

J-Gamer
Member #12,491
January 2011
avatar

This file works for me in Ubuntu 11.10.

#!/bin/sh
touch "blargh"
rm blargh

Does msys have rm? Try the steps of the program manually on the command-line.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

William Labbett
Member #4,486
March 2004
avatar

Manually it works okay but not from the script.

jmasterx
Member #11,410
October 2009

On Windows, I think the command is 'rmdir' if you're on Windows maybe that's why it is not working?

William Labbett
Member #4,486
March 2004
avatar

I tried that. command not found again.

Dario ff
Member #10,065
August 2008
avatar

rd?

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

jmasterx
Member #11,410
October 2009

As well as to be restricting yourself to Windows, you might as well do it right and use RemoveDirectory http://msdn.microsoft.com/en-us/library/aa365488%28VS.85%29.aspx

Or this for non-empty directories:

#SelectExpand
1void silently_remove_directory(LPCTSTR dir) // Fully qualified name of the directory being deleted, without trailing backslash 2{ 3 SHFILEOPSTRUCT file_op = { 4 NULL, 5 FO_DELETE, 6 dir, 7 "", 8 FOF_NOCONFIRMATION | 9 FOF_NOERRORUI | 10 FOF_SILENT, 11 false, 12 0, 13 "" }; 14 SHFileOperation(&file_op); 15}

gnolam
Member #2,030
March 2002
avatar

jmasterx said:

On Windows, I think the command is 'rmdir'

rd.
rd /s for a recursive delete including all files (equivalent to UNIX's rm -r). rd /s /q for recursive delete in quiet mode (don't ask for permission before deleting stuff - equivalent to UNIX's rm -rf).

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Sirocco
Member #88
April 2000
avatar

Remove is portable, and although I haven't tried to use it in that fashion, is supposedly able to remove directories as well as files. I'm not sure if it can get the directory and all the files in one shot, but it'd be worth trying.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

William Labbett
Member #4,486
March 2004
avatar

Thanks jmasterx.

I got that to work..

I'm still puzzled about why none of rm -rf, rmdir, or rd work when other commands like

cd work fine.

J-Gamer
Member #12,491
January 2011
avatar

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Trent Gamblin
Member #261
April 2000
avatar

cd works because it's both a bash and cmd.exe command. rmdir and rd don't work in bash because they're not bash commands. rm doesn't work because you don't have rm installed. You can get many unix utils like rm for Windows here.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: