A
A
Alexander Bondarenko2019-04-10 20:22:29
C++ / C#
Alexander Bondarenko, 2019-04-10 20:22:29

How can I get the file size?

I get the parameters from the cmd command line and display them, then I need to find the file with the largest size in this folder from which the script is launched, the question is how can I get the size of the largest file?

#include <iostream.h>
#include <filesystem>
using namespace std;

int main(int argc, char *argv[])
{
  for(int i=0;i<argc;i++)
  {
    cout<<"Argument"<<i<<":"<<argv[i]<<endl;
  }
  for (directory_iterator itr(directory_entry); itr!=directory_iterator(); ++itr)
  {
    
  }
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2019-04-10
@bond_1013

In my noobish opinion, something like this (only return your path to its place):

#include <iostream>
#include <filesystem>
#include <string>
using namespace std;
using namespace std::filesystem;

int main(int argc, char *argv[])
{
  for (int i = 0; i < argc; i++)
  {
    cout << "Argument" << i << ":" << argv[i] << endl;
  }
  uintmax_t i_MaxFileSize = 0;
  string s_MaxFileName="";
  for (directory_iterator itr("e:\\video\\"); itr != directory_iterator(); ++itr)
  {
    if (itr->is_directory())continue;
    if (itr->file_size() > i_MaxFileSize)
    {
      i_MaxFileSize = itr->file_size();
      //s_MaxFileName = itr->path().string(); полный путь
      s_MaxFileName = itr->path().filename().string();//только имя файла
    }
  }
  cout << "The max file size is " << s_MaxFileName << endl;
  return 0;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question