Don't like ads? PRO users don't see any ads ;-)
Guest

Java copy.

By: a guest on Jun 21st, 2012  |  syntax: Java  |  size: 0.90 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.File;
  2.  
  3. public class renamer
  4. {
  5.  
  6.  public static void main(String[] args)
  7. {
  8.  
  9.   // Directory path here
  10.   String path = "C:\\Users\\wildcat\\Desktop\\renameinput";
  11.  
  12.   String files;
  13.   File folder = new File(path);
  14.   File[] listOfFiles = folder.listFiles();
  15.  
  16.   //Find files to process, list them.
  17.   for (int i = 0; i < listOfFiles.length; i++)
  18.   {
  19.  
  20.    if (listOfFiles[i].isFile())
  21.    {
  22.    files = listOfFiles[i].getName();
  23.        if (files.endsWith(".txt") || files.endsWith(".TXT"))
  24.        {
  25.           System.out.println(files);
  26.         }
  27.      }
  28.   }
  29.  
  30.   for (int i = 0; i < listOfFiles.length; i++)
  31.   {
  32.           File oldFile = new File(listOfFiles[i].getName());
  33.           System.out.println(listOfFiles[i].getName());
  34.           boolean happen = oldFile.renameTo(new File("C:\\Users\\wildcat\\Desktop\\renameoutput" + oldFile.getName()));
  35.           System.out.println(happen);
  36.   }
  37.  
  38. }
  39. }