development – How to get all the files from specific sharepoint folders and subfolders using CSOM

Below is the CSOM code to get the list of files in a folder in SharePoint online library.

static void Main(string() args)
{
    string userName = "<user name>";
    string password = "<password>";
    var securePassword = new SecureString();
    foreach (char c in password)
    {
        securePassword.AppendChar(c);
    }
    using (ClientContext cxt = new ClientContext("<your site URL>"))
    {
        cxt.Credentials = new SharePointOnlineCredentials(userName, securePassword);
        Web web = cxt.Web;
        cxt.Load(web, a => a.ServerRelativeUrl);
        cxt.ExecuteQuery();
        List list = cxt.Web.Lists.GetByTitle("<your library name >");
        cxt.Load(list);
        cxt.Load(list.RootFolder);
        cxt.Load(list.RootFolder.Folders);
        cxt.Load(list.RootFolder.Files);
        cxt.ExecuteQuery();
        FolderCollection fcol = list.RootFolder.Folders;
        List<string> lstFile = new List<string>();
        foreach (Folder f in fcol)
        {
            if (f.Name == "<your folder name>")
            {
                cxt.Load(f.Files);
                cxt.ExecuteQuery();
                FileCollection fileCol = f.Files;
                foreach (File file in fileCol)
                {
                    lstFile.Add(file.Name);
                }
            }
        }
    }
}