Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, Nymphodora, Quad, TipmyPip, Imhotep), 852 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Delete a Directory? #472875
05/27/18 10:48
05/27/18 10:48
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Is there any way to delete a directory in lite-C?

I found "file_delete" but cannot find anything similar for directories.

I am able to create a directory in the following somewhat messy way...

Quote:

//NEW FOLDER OPTION - Creates a folder name based on user input
str_cpy(save_dir,level_string);

compatibility = 8;

galaxy_write = file_open_write("Save_Test.txt");

file_str_write(galaxy_write,"SAVE TEST");//creates a file in order to
//actually create the folder

file_str_write(galaxy_write,",");

file_close(galaxy_write);

compatibility = 10;//resumes normal compatibility


If there's a better way to do it, I would love to know that too.

However, once it's there, I have found that I cannot get rid of it without manually deleting through Windows.

Re: Delete a Directory? [Re: Dooley] #472881
05/27/18 21:57
05/27/18 21:57
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Did you try RemoveDirectory function from windows.h? Directory must be empty if you gonna use this function. So you should first delete the files in the directory i guess.

Re: Delete a Directory? [Re: Emre] #472882
05/28/18 05:03
05/28/18 05:03
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
Thanks! This offers two unique challenges, as the directory will have a number of files in it, and I don't think I've ever used a command through Windows.h. However, I will look into it!

Re: Delete a Directory? [Re: Dooley] #472883
05/28/18 07:41
05/28/18 07:41
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Okay. I will give you a function. This function remove all files from directory.

Code:
int iffile_exist(char* fileName) 
{
	long fileAttr;
	fileAttr = GetFileAttributes(fileName);
	if (0xFFFFFFFF == fileAttr)
	return 0;
	return 1;
}

STRING* str_temp="";
STRING* str_folder_temp="";
WIN32_FIND_DATA file_handle;
HANDLE FolderHandle;

function remove_all_files_fromfolder(STRING* folder)
{

	str_cpy(str_folder_temp,folder);
	str_cat(str_folder_temp,"*.*");//all files

	FolderHandle = FindFirstFile(_chr(str_folder_temp),&file_handle);
	if ( INVALID_HANDLE_VALUE == FolderHandle ) 
	{
		printf("No file or directory");
		return -1;
	}
	while(1)
	{
		
		str_cpy(str_temp,folder);
		str_cat(str_temp,file_handle.cFileName);
		//printf(_chr(str_temp));
		if(iffile_exist(_chr(str_temp))==1)//if file exist
		{
			file_delete(str_temp);
		}
		
		if ( FindNextFile(FolderHandle, &file_handle )== 0 )
		{
			break;	
		}
		
	}

}
function on_1_event()
{
	remove_all_files_fromfolder("G://2015//Aynalar//aaa//");	
}


You have to use two slash for folder adress. the forum does not allow me to write two slashes side by side. Here is what i'm talking about:


Then you can try to use RemoveDirectory function.

Last edited by Emre; 05/28/18 08:06.
Re: Delete a Directory? [Re: Emre] #472892
05/28/18 18:32
05/28/18 18:32
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
You are awesome, thanks!

Re: Delete a Directory? [Re: Dooley] #472893
05/28/18 18:57
05/28/18 18:57
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline OP
User
Dooley  Offline OP
User

Joined: May 2005
Posts: 868
Chicago, IL
This is really great, and in fact it solves my whole problem. It was the files in that directory that really needed to be deleted, the directory itself can actually stay with no problems.

Re: Delete a Directory? [Re: Dooley] #472895
05/28/18 19:10
05/28/18 19:10
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Good to hear that! I'm always glad to help.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1