Recently, I came across a useful command for finding the file size in cmd. I just wanted to implement it from c++ windows forms. So I created a form and added a textbox,button and a label. The textbox takes the file name as input and is stored in fname variable. The label displays any errors or the file size.
The click event of the button contains this code:
const char* str;
const char* val;
fname=txtFname->Text;
lblInfo->Enabled = true;
lblInfo->Visible = true;
if(fname=="")
{
lblInfo->Text = "Enter a valid file name";
}
else
{
cmnd=L"for %I in ("+fname+") do @echo %~zI";
str = (const char*) (Marshal::StringToHGlobalAnsi(cmnd)).ToPointer();
lblInfo->Text = L"Size of file is: "+system(str)+" bytes";
}
The function system returning the exit code and not the size of the file.
How can I get the output of a command in cmd?
I must get the output of the command and display it in the label "lblInfo"..