Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function that reads the file system of directories including subdirectories and prints the names of the files/folders along with the size. You will

Write a function that reads the file system of directories including subdirectories and prints the names of the files/folders along with the size. You will be using Lab7 Ex2 coding. Note that, Lab7 Ex2 code prints the names of the files and folders, it skips reading the subfolders. The following lines of code checks for subfolders.

Node h = FindFirstFile(fname.c_str(), &data);

if (isDirectory(data) && !isHiddenDirectory(data) && !isSymbolicLink(data) && !isDotDirectory(data))

Refer to Appendix for further instruction. A sample output: image text in transcribed

Appendix :

#include

#include

#include

usingnamespacestd;

#defineData WIN32_FIND_DATA

#defineSize __int64

#defineBigSize LARGE_INTEGER

#defineNode HANDLE

#defineisInvalid(h) (h == INVALID_HANDLE_VALUE)

#defineisDirectory(data) (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)

#defineisDotDirectory(data) (strcmp(data.cFileName,".")==0 || strcmp(data.cFileName,"..")== 0)

#defineisHiddenDirectory(data) (data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)

#defineisSymbolicLink(data) (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)

SizeGetFileSize(Datadata) {

BigSizesz;

// Since file sizes can be larger than 2GB, the size is reported as two DWORD objects.

// Below we combine them to make one 64-bit integer.

sz.LowPart = data.nFileSizeLow;

sz.HighPart = data.nFileSizeHigh;

returnsz.QuadPart;

}

SizeTransverseDirectory(stringpath,intspaces=0) {

Datadata;

stringfname = path+"\\*.*";

Nodeh = FindFirstFile(fname.c_str(), &data);

if(!isInvalid(h)) {

do{

if(isDirectory(data) && !isHiddenDirectory(data) && !isSymbolicLink(data) && !isDotDirectory(data)) {

// process directory (recursively)

}

else{

// process file

}

} while(FindNextFile(h, &data) != 0);

FindClose(h);

}

voidmain()

{

string path= " Write your path here";

cout

cout

}

ClUserslpkolli Desktop Fall18)CMP120L-sec1-sec2-DrRaafat trialDebugltrial.exe 305L-LA1-C++ Review-S18.docx-->34064 CMP 305L-Lab7-RecursionAdvanced.docx-->99827 CMP 305L-Lab8-BST-ver2.docx-->31129 CMP 305L-Lab8-BST.docx-->31140 C:\Userspkolli\Desktop\CMP305 Solutions C:\Users pkolli\DesktoplCMP3051Solutions\ Lab2 C:\Users pkolli\DesktoplCMP305 Solutions\ Lab21Q1 Driver.cpp--4009 TelDir.h-->798 C:\UsersIpkolli\Desktop\CMP305 Solutions \Lab2102 driver.cpp-->1084 input.txt-->67 C:\Users pkolli\DesktoplCMP305 Solutions\ Lab21Q3 ArrayIterator.h-->1074 Driver.cpp-->264 Lab2-Sol.docx--139890 Lab3-Sol.docx->233505 Lab4-sol.docx-->28273 C:\Users pkolli\Desktop\CMP3051Solutions\Projectl C:\Users pkolli\Desktop\CMP3051Solutions\Project1\Project1 Project1.vcxproj- ->6012 Project1.vcxproj.filters--1074 Project1.vcxproj.user--165 Source.cpp9479 Text.txt-->397 $P 305L-Lab8-BST-ver2.docx-->162 $P 305L-Lab8-BST.docx-->162 Total Size of the directoryC:\Users pkolli\Desktop\CMP3051 is 622575 Press any key to continue ClUserslpkolli Desktop Fall18)CMP120L-sec1-sec2-DrRaafat trialDebugltrial.exe 305L-LA1-C++ Review-S18.docx-->34064 CMP 305L-Lab7-RecursionAdvanced.docx-->99827 CMP 305L-Lab8-BST-ver2.docx-->31129 CMP 305L-Lab8-BST.docx-->31140 C:\Userspkolli\Desktop\CMP305 Solutions C:\Users pkolli\DesktoplCMP3051Solutions\ Lab2 C:\Users pkolli\DesktoplCMP305 Solutions\ Lab21Q1 Driver.cpp--4009 TelDir.h-->798 C:\UsersIpkolli\Desktop\CMP305 Solutions \Lab2102 driver.cpp-->1084 input.txt-->67 C:\Users pkolli\DesktoplCMP305 Solutions\ Lab21Q3 ArrayIterator.h-->1074 Driver.cpp-->264 Lab2-Sol.docx--139890 Lab3-Sol.docx->233505 Lab4-sol.docx-->28273 C:\Users pkolli\Desktop\CMP3051Solutions\Projectl C:\Users pkolli\Desktop\CMP3051Solutions\Project1\Project1 Project1.vcxproj- ->6012 Project1.vcxproj.filters--1074 Project1.vcxproj.user--165 Source.cpp9479 Text.txt-->397 $P 305L-Lab8-BST-ver2.docx-->162 $P 305L-Lab8-BST.docx-->162 Total Size of the directoryC:\Users pkolli\Desktop\CMP3051 is 622575 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago