Results 1 to 3 of 3

Thread: Comapre script

  1. #1
    Private First Class RobsoN's Avatar
    Join Date
    Jan 2013
    Location
    /home/cod2/
    Posts
    230
    Thanks
    119
    Thanked 95 Times in 64 Posts

    Comapre script

    Hello I need fast script (in Android) which returns missing/outdated files in phone directory. This is my code, but it's pretty slow .

    PHP Code:
    public List<String_GetMissingFiles()
    {
     
    int checked_files 0;
     
     List<
    String_Local_Files getLocalFiles(new File(Config._SDCARD_DIR), null);
     List<
    String_FTP_Files getFTPfiles();
     List<
    String_Files_Need = new ArrayList<String>();
     
     try{
         for(
    int i  0< + _FTP_Files.size(); i++){
             
             
    boolean found false;
             
    double progress = (Double.valueOf(checked_files) / Double.valueOf(_FTP_Files.size()));
             
    String[] _FTP_File_st strTok(_FTP_Files.get(i), ";");
             
    String _FTP_File _FTP_File_st[0];
             
    Date _FTP_File_date = new SimpleDateFormat("yyyy-MM-dd").parse(_FTP_File_st[1]);
             
             
    FTP_SyncThread.doProgress("*"+_FTP_File);
             
    FTP_SyncThread.doProgress("^"+(_FTP_Files.size() - checked_files));
             
    FTP_SyncThread.doProgress("["+progress);
             
    Log.d("FTP","checked: "+checked_files" max: "+_FTP_Files.size());
             
             for(
    int x 0< + _Local_Files.size(); x++){
                 
                 
    String[] _Local_File_st strTok(_Local_Files.get(x), ";");
                 
    String _Local_File _Local_File_st[0];
                 
    Date _Local_File_date = new SimpleDateFormat("yyyy-MM-dd").parse(_Local_File_st[1]);
                 
                 if(
    _FTP_File.equals(_Local_File)) //Found file, now check date
                 
    {
                     if(
    _FTP_File_date.compareTo(_Local_File_date) <= 0)
                     {
                         
    //DATE OK
                         
    found true;
                         
    //Log.i("FTP","[OK]: File Found: "+_FTP_File);
                         
    break;
                     }
                 } 
             }
             
             
    checked_files += 1;
             
             if(!
    found)
             {
                 
    //Log.w("FTP","[ERR]: File Not Found or outdated: "+_FTP_File);
                 
    _Files_Need.add(_FTP_File);
             }
         }
     }
     catch (
    ParseException e) {
            
    Log.e("FTP","Catch error: "+e.getMessage());
        }

     return 
    _Files_Need;

    It's like loop in loop, that's why it's slow . Any better ideas?

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,013
    Thanks
    2,109
    Thanked 1,086 Times in 753 Posts
    Since your lists can only hold strings, I guess you are retrieving the last modification time in each iteration? That would be slow (filesystem + remote ftp). Better to retrieve every date (local + ftp) and save it in an array with a structure for two fields (string name, date lastModification) and just compare those two arrays.
    timescale 0.01

  3. #3
    Private First Class RobsoN's Avatar
    Join Date
    Jan 2013
    Location
    /home/cod2/
    Posts
    230
    Thanks
    119
    Thanked 95 Times in 64 Posts
    Thanks for fast reply.
    I guess you are retrieving the last modification time in each iteration?
    Nope, I'm getting all data here:

    PHP Code:
     List<String_Local_Files getLocalFiles(new File(Config._SDCARD_DIR), null);  //Getting array with Local Files in phone files names + files date eg. "/00/22.jpg;2012-04-13"
     
    List<String_FTP_Files getFTPfiles();  //Array with FTP files names + files date eg. "/00/20.jpg;2012-06-13"
     
    List<String_Files_Need = new ArrayList<String>(); //new array 
    Better to retrieve every date (local + ftp) and save it in an array with a structure for two fields (string name, date lastModification) and just compare those two arrays.
    Can you give me some example? I'm new in Java, so i can't understand everything. I'm already comparing two arrays: 1.Check if filename in array1 equals in array2 (same file), then file exist, else - [Add missing file]. 2.Compare date in array1 to array2, if date in local array is < (older) than date in ftp array - [Add missing file]

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •