水曜日, 3月 11, 2009

Java: ディレクトリ比較

今日はちょっと会社でいやなことがあったので...

言いたいことも言えず。

だから...Javaで書いて、動くのを確認 (こうでなきゃ)。

やっぱりJavaはいい。

単なる、ディレクトリ比較のプログラムです。



/* Compare.java -- directory comparison program
*
* Copyright (C) 2009 Erica Asai

* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/

import java.io.*;

public class Compare
{
public void compare(String src, String dest)
{
try
{
File srcDir=new File(src);
if(!srcDir.isDirectory())
{
return;
}
File destDir=new File(dest);
if(!destDir.isDirectory())
{
return;
}
String srcList[]=srcDir.list();
String destList[]=destDir.list();
for(int i=0;i<srcList.length;i++)
{
int j=0;
while(!destList[j].equals(srcList[i]) && ++j<destList.length);
if(destList.length<=j)
{
System.out.println("(-)"+src+"\\"+srcList[i]);
}
else
{
compare(src+"\\"+srcList[i],dest+"\\"+destList[j]);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void main(String args[])
{
Compare compare=new Compare();
if(2==args.length)
{
String src=args[0];
String dest=args[1];
compare.compare(src,dest);
}
}
}


Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...