Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Checks if a directory exists.
- bool path_exists(char *directory)
- {
- DWORD returnvalue;
- returnvalue = GetFileAttributes(directory);
- if(returnvalue == ((DWORD)-1))
- {
- return false;
- }
- return true;
- }
- //Checks if path refers to a letter drive instead of a sub-directory.
- bool is_letter_drive(char *path)
- {
- char i;
- char* temp_path;// = new char[256];
- for(i = 'A'; i <= 'Z'; i++)
- {
- temp_path = g_strdup_printf ("%c:", i);//sprintf(temp_path, "%c:", i);
- if(strcmp(path, temp_path) == 0)
- {
- g_free (temp_path);//Not needed without Gtk
- break;
- }
- g_free (temp_path);//Not needed without Gtk
- temp_path = g_strdup_printf ("%c:", tolower(i));//sprintf(temp_path, "%c:", tolower(i));
- if(strcmp(path, temp_path) == 0)
- {
- g_free (temp_path);//Not needed without Gtk
- break;
- }
- g_free (temp_path);//Not needed without Gtk
- }
- if(i <= 'Z')
- {
- return true;
- }
- return false;
- }
- //Attempts to create a directory based on path. Returns false if unsuccessful. Supports recursive directories.
- bool create_directory(char *path)
- {
- int i = 0;
- char *sub = new char[strlen(path) + 1];
- for(i; i < strlen(path); i++)
- {
- if(path[i] == '\\')
- {
- sub[i] = '\0';
- if(!is_letter_drive(sub))
- {
- if(!path_exists(sub) && !CreateDirectory(sub, NULL))
- {
- return false;
- }
- }
- }
- sub[i] = path[i];
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment