fileinfo.java /* * Copyright (c) 2001-2005 Servertec. All Rights Reserved. * * 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 * * THIS NOTICE MUST NOT BE ALTERED NOR REMOVED. * * CopyrightVersion 1.0 */ import java.util.Date; import stec.sfc.Win32.File; import stec.sfc.Win32.FileAttribute; public class fileinfo { public static void main(String[] args) throws Exception { if(args == null) { syntax("file was not specified."); return; } if(args.length < 1) { syntax("file was not specified."); return; } System.out.println("File Name: " + args[0]); File file = new File(args[0]); int attributes = file.getAttributes(); if(!file.exists()) { System.out.println("file does not exist."); System.out.println(); return; } System.out.println("Creation Time: " + new Date(file.getCreationTimeEx())); System.out.println("Last Modified Time: " + new Date(file.getLastModifiedTimeEx())); System.out.println("Last Accessed Time: " + new Date(file.getLastAccessedTimeEx())); if((attributes & FileAttribute.DIRECTORY) == 0) { System.out.println("Length: " + file.length()); if((attributes & FileAttribute.COMPRESSED) == FileAttribute.COMPRESSED) { System.out.println("Compressed Length: " + file.getCompressedLength()); } } System.out.println("Long Path Name: " + file.getLongPathName()); System.out.println("Short Path Name: " + file.getShortPathName()); System.out.print("File Attributes:"); if((attributes & FileAttribute.ARCHIVE) == FileAttribute.ARCHIVE) { System.out.print(" Archive"); } if((attributes & FileAttribute.COMPRESSED) == FileAttribute.COMPRESSED) { System.out.print(" Compressed"); } if((attributes & FileAttribute.DIRECTORY) == FileAttribute.DIRECTORY) { System.out.print(" Directory"); } if((attributes & FileAttribute.ENCRYPTED) == FileAttribute.ENCRYPTED) { System.out.print(" Encrypted"); } if((attributes & FileAttribute.HIDDEN) == FileAttribute.HIDDEN) { System.out.print(" Hidden"); } if((attributes & FileAttribute.NORMAL) == FileAttribute.NORMAL) { System.out.print(" Normal"); } if((attributes & FileAttribute.NOT_CONTENT_INDEXED) == FileAttribute.NOT_CONTENT_INDEXED) { System.out.print(" Not_Content_Indexed"); } if((attributes & FileAttribute.OFFLINE) == FileAttribute.OFFLINE) { System.out.print(" Offline"); } if((attributes & FileAttribute.READONLY) == FileAttribute.READONLY) { System.out.print(" Readonly"); } if((attributes & FileAttribute.REPARSE_POINT) == FileAttribute.REPARSE_POINT) { System.out.print(" Reparse_Point"); } if((attributes & FileAttribute.SPARSE_FILE) == FileAttribute.SPARSE_FILE) { System.out.print(" Sparse_File"); } if((attributes & FileAttribute.SYSTEM) == FileAttribute.SYSTEM) { System.out.print(" System"); } if((attributes & FileAttribute.TEMPORARY) == FileAttribute.TEMPORARY) { System.out.print(" Temporary"); } System.out.println(); System.out.println(); } static void syntax() { System.out.println("usage: <javavm> fileinfo <file>"); System.out.println(); } static void syntax(String message) { syntax(); if(message != null) { System.out.println(message); } System.out.println(); } }