Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- public class Main {
- private static String DATAIN = "data/dirfrom";
- private static String DATATO = "data/dirto/";
- public static void main(String[] args) throws IOException {
- findDocuments(DATAIN, DATATO);
- }
- public static void findDocuments(String in, String out) throws IOException {
- File fin = new File(in);
- File fout = new File(out);
- File[] alldat = fin.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".xlsx") || name.endsWith(".doc");
- }
- });
- if (!fin.exists()) {
- System.out.println("ne postoi");
- return;
- }
- if (fout.exists()) {
- for (File f : fout.listFiles()) {
- f.delete();
- }
- }
- if (alldat.length > 0) {
- for (File f : alldat) {
- if (f.length() > 500000) {
- moveFile(f, out+"//dokumenti");
- } else{
- writeToDatabase(f,out+"//brisenje.txt");
- }
- }
- } else {
- System.out.println("Ne postoi nitu eden file so ekstenzija .xls ili .doc");
- }
- }
- private static void writeToDatabase(File f, String out) throws IOException {
- try(
- RandomAccessFile randomAccessFile = new RandomAccessFile(out,"rw");
- ){
- randomAccessFile.seek(0);
- randomAccessFile.writeUTF(f.getName());
- randomAccessFile.writeInt((int) (f.length() * 1000));
- }
- }
- public static boolean moveFile(File file, String newparent) {
- return moveFileandRename(file, newparent, file.getName());
- }
- public static boolean moveFileandRename(File file, String newParent, String newName) {
- File parent = new File(newParent);
- if (!parent.isDirectory()) {
- System.out.println("Ne Postoi PARENT!");
- return false;
- }
- File renamedfile = new File(parent, newName);
- if (renamedfile.exists()) {
- System.out.println("OVOJ FILE VEKE POSTOI");
- return false;
- }
- return file.renameTo(renamedfile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement