void gphoto2()
{
    cout << endl;
    cout << "Reading contents of camera to gphoto2.list..." << endl;
    gSystem->Exec("gphoto2 --list-files > gphoto2.list");

    cout << endl;

    ifstream fin("gphoto2.list");

    TString dir;
    while (1)
    {
        TString str;
        str.ReadLine(fin);
        if (!fin)
            break;

        Int_t first = str.First('»')+1;

        if (first>0)
        {
            dir = str(first, str.Last('«')-first);
            continue;
        }
        if (str[0]=='#')
        {
            int num, size;
            char n[256], type[256];
            sscanf(str.Data()+1, "%d %s %*s %d %*s %s",
                   &num, n, &size, type);

            TString name(n);
            name.ReplaceAll(".JPG", ".txt");
            name.ReplaceAll(".AVI", ".txt");

            cout << "Found: #" << num << " " << dir << "/" << n << " (" << type << ")  -  " << size << " kB" << endl;

            //TString cmd = Form("gphoto2 --folder %s --get-file %d --get-thumbnail %d --show-info %d --show-exif %d --force-overwrite > %s 2>> gphoto2.log", dir.Data(), num, num, num, num, name.Data());
            TString cmd = Form("gphoto2 --get-file %d --get-thumbnail %d --show-info %d --show-exif %d --force-overwrite > %s 2>> gphoto2.log", num, num, num, num, name.Data());
            gSystem->Exec(cmd.Data());
            continue;
        }

    }

    cout << "Logging written to gphoto2.log." << endl << endl;
    cout << "Done." << endl << endl;

    cout << "Counting thumb_IMG_*.jpg" << endl;
    gSystem->Exec("ls -1 thumb_IMG_*.jpg | wc -l");
    cout << "Counting IMG_*.JPG" << endl;
    gSystem->Exec("ls -1 IMG_*.JPG | wc -l");
    cout << "Counting IMG_*.txt" << endl;
    gSystem->Exec("ls -1 IMG_*.txt | wc -l");
    cout << endl << endl;
}

