Saturday, October 18, 2014

Listing Files and Folders

Recently my friend had developed a tool which will compare the files and try to list duplicate files also it will help the user to delete such files (http://www.shishirprasad.net/2014/09/learnings-from-diffing-tool.html) . So after reading his blog I also got motivated to develop my own tool for a practical problem.

I have created C drive with less hard disk space when compared to other drives. So now and then it gets filled up and goes to danger red mark. During those times I had to search for files and folders in C drive and delete unwanted among them. My search criteria will be finding those folders whose size is huge and try to delete files and folders inside them.

Currently UI of the tool is complete. It is having two stage. The first dialog will get the search criteria. When user presses OK in this dialog based on the user inputs it will form a Search Criteria structure -

typedef struct SearchFilesFolders
{
bool bHiddenFiles;
bool bReadOnlyFiles;
__int64 nMaxSize;
__int64 nMinSize;
bool bSearchForMaxSize;
bool bSearchForMinSize;
bool bCreationDateGreater;
bool bCreationDateLesser;
bool bModificationGreater;
bool bModificationLesser;
SYSTEMTIME systimeCreationDate;
SYSTEMTIME systimeModificationDate;
WCHAR* location;


}SEARCHFILEFOLDER;

User can form different conditions for searching files and folders like search only hidden files or search files whose size is greater than 100kb or search files whose size is lesser than 100 kb or find the files whose creation date is greater than or lesser than certain date. It can be combination of all of them or some of them.



The second UI is the dialog which will show the results based on the search condition set in the previous dialog. Dialog will have 2 sections 1st is a tree view of the files and folders, 2nd is a readonly edit box which will have the details of the files and folders which was selected in the tree view.

Now I am able to search the path select the folders and files which are meeting the condition. I am now able to display them in tree view. There are issues like I wanted to display 2 different icons for folder and file but currently it is not happening properly. Also it is crashing in many places. still displaying the details of the selection in Tree View at bottom readonly edit control has to be done.

Every File and Folder will have following structure -

typedef struct FileInfo
{
__int64 dwFileSize;
WCHAR* strFileName;
WCHAR* location;
DWORD dwFileAttributes;
bool bHidden;
bool bReadonly;
FILETIME ftCreationTime;
FILETIME ftModificationTime;
bool bIsFile;
bool bError;
struct FileInfo* ParentFolder;
struct LstFileInSubFolder* ChildElements;
PWIN32_FIND_DATA actualData;
}FILEINFO;

And I am forming a list of file folder structure with root as the "Search location folder" given in the previous UI.

typedef struct LstFileInSubFolder
{
FILEINFO* fileFolder;
struct LstFileInSubFolder* nextFileFolder;
}LSTFILEINSUBFOLDER;

Still lot of issues are there that needs to be fixed. I will come back soon.

Source code at this stage is - https://github.com/harsha-kadekar/ListFilesFolders.git

I will come back soon with the complete developed code.