|
Delete a Directory?
#472875
05/27/18 10:48
05/27/18 10:48
|
Joined: May 2005
Posts: 868 Chicago, IL
Dooley
OP
User
|
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... //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
User
|
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: Dooley]
#472883
05/28/18 07:41
05/28/18 07:41
|
Joined: Jul 2007
Posts: 619 Turkey, Izmir
Emre
User
|
User
Joined: Jul 2007
Posts: 619
Turkey, Izmir
|
Okay. I will give you a function. This function remove all files from directory.
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.
|
|
|
|