วันเสาร์ที่ 16 เมษายน พ.ศ. 2559

Sync File and Directory by using Apache FileUtils

package com.ac;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;


public class FileSyncApp
{

    public static void main(String[] args) throws Exception
    {

        String sourcePath = "E:/03_Movie";
        String destinationPath = "H:/03_Movie";

        List sourceFileList = (List) FileUtils.listFiles(new File(sourcePath), null, true);

        List sourceFilePathList = new ArrayList();
        for (File sourceFile : sourceFileList)
        {
            String filePath = sourceFile.getAbsolutePath();
            filePath = filePath.replace("\\", "/");
            filePath = filePath.replace(sourcePath, "");
            // System.out.println("sourceFilePath=" + filePath);

            sourceFilePathList.add(filePath);
        }

        /*
         * Delete an unexist file in destination path
         */
        List destinationFileList = (List) FileUtils.listFiles(new File(destinationPath), null, true);


        for (File destinationFile : destinationFileList)
        {
            String filePath = destinationFile.getAbsolutePath();
            filePath = filePath.replace("\\", "/");
            filePath = filePath.replace(destinationPath, "");

            /*
             * Delete non-exists file
             */
            if (!sourceFilePathList.contains(filePath))
            {
                if (destinationFile.delete())
                {
                    System.out.println("deleted=" + filePath);

                }
            }

        }

        System.out.println("Start comparing file");
        for (String sourceFilePath : sourceFilePathList)
        {

            File sourceFile = new File(sourcePath + sourceFilePath);
            // System.out.println(sourceFile.getAbsolutePath());


            File destinationFile = new File(destinationPath + sourceFilePath);
            if (destinationFile.exists())
            {

                long sourceFileSize = FileUtils.sizeOf(sourceFile);
                long destinationFileSize = FileUtils.sizeOf(destinationFile);

                if (FileUtils.isFileNewer(sourceFile, destinationFile) || FileUtils.isFileOlder(sourceFile, destinationFile))
                {
                    destinationFile.delete();
                    System.out.println("Modified-Date diff, Delete File=" + destinationFile.getAbsolutePath());
                } else if (sourceFileSize != destinationFileSize)
                {
                    destinationFile.delete();
                    System.out.println("Size diff, Delete File=" + destinationFile.getAbsolutePath());
                } else
                {
                    continue;
                }

            }

            System.out.println("I:Copy File=" + destinationFile.getAbsolutePath());
            FileUtils.copyFile(sourceFile, destinationFile, true);
            System.out.println("O:Copy File=" + destinationFile.getAbsolutePath());


        }

        System.out.println("Done");
    }


}

วันอังคารที่ 12 เมษายน พ.ศ. 2559

Cafe for Pantip™ (No Ads) Cafe for Pantip™

Version 9.04
-Theme สีดำสนิท
-Facebook Pages
 (Pantip.com, พันทิปนานุกรม, กระทู้เด็ดพันทิป, ก้นครัวไม่กลัวหิว, บลูแพลนเน็ต เบ็ดเสร็จเรื่องเที่ยว, Inspired by ชายคา)
-สามารถเปิดกระทู้ http://2g.pantip.com ได้
-Upgrade Android support lib, google play lib

https://play.google.com/store/apps/details?id=com.ao.reader