├── .gitignore
├── src
└── hamid
│ ├── main.css
│ ├── Main.java
│ ├── CustomFileVisitor.java
│ ├── main.fxml
│ ├── Controller.java
│ └── DefaultFileVisitor.java
├── out
├── artifacts
│ └── File_Organizer
│ │ ├── File_Organizer.jar
│ │ ├── File_Organizer.jnlp
│ │ └── File_Organizer.html
└── production
│ └── File Organizer
│ └── hamid
│ ├── Main.class
│ ├── main.css
│ ├── Controller.class
│ ├── CustomFileVisitor.class
│ ├── DefaultFileVisitor.class
│ └── main.fxml
├── File Organizer.iml
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | /out/artifacts/File_Organizer.html
3 | /out/artifacts/File_Organizer.jnlp
--------------------------------------------------------------------------------
/src/hamid/main.css:
--------------------------------------------------------------------------------
1 | .text{
2 | -fx-font-size: 20px;
3 | -fx-font-weight: bold;
4 | }
5 | .root {
6 | -fx-background-color: #7fffd4;
7 | }
--------------------------------------------------------------------------------
/out/artifacts/File_Organizer/File_Organizer.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inventionsbyhamid/File-Organizer/HEAD/out/artifacts/File_Organizer/File_Organizer.jar
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inventionsbyhamid/File-Organizer/HEAD/out/production/File Organizer/hamid/Main.class
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/main.css:
--------------------------------------------------------------------------------
1 | .text{
2 | -fx-font-size: 20px;
3 | -fx-font-weight: bold;
4 | }
5 | .root {
6 | -fx-background-color: #7fffd4;
7 | }
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/Controller.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inventionsbyhamid/File-Organizer/HEAD/out/production/File Organizer/hamid/Controller.class
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/CustomFileVisitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inventionsbyhamid/File-Organizer/HEAD/out/production/File Organizer/hamid/CustomFileVisitor.class
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/DefaultFileVisitor.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inventionsbyhamid/File-Organizer/HEAD/out/production/File Organizer/hamid/DefaultFileVisitor.class
--------------------------------------------------------------------------------
/File Organizer.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # File-Organizer
2 | Organize files in any directory by classifying them into different folders.
3 | This project is inspired by https://github.com/bhrigu123/classifier.
4 |
5 | ## Requirements
6 | * Java Runtime Environment
7 |
8 | ##Installation
9 | * Download the jar [File_Organizer.jar](https://www.dropbox.com/s/weanvnxap6s0080/File_Organizer.jar?dl=1)
10 | * Double click to run
11 |
12 | ##Usage
13 | Default:
14 | * Select folder to organize clcik Organize button to classify files in Music,Archives,Documents,Pictures,Videos
15 |
16 | Custom:
17 | * Enter the folder name and then extension list separated by commas. Example html,css,js
18 |
19 | ####Note: Extensions should not contain the "." prefix.
20 | 
21 |
22 | ##TODO:
23 | * Separate moving files code in separate background thread.
24 |
--------------------------------------------------------------------------------
/src/hamid/Main.java:
--------------------------------------------------------------------------------
1 | package hamid;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXML;
5 | import javafx.fxml.FXMLLoader;
6 | import javafx.scene.Parent;
7 | import javafx.scene.Scene;
8 | import javafx.scene.text.Text;
9 | import javafx.stage.Stage;
10 |
11 | public class Main extends Application {
12 | @FXML private Text done;
13 |
14 |
15 | @Override
16 | public void start(Stage primaryStage) throws Exception{
17 | Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
18 | primaryStage.setTitle("File Organizer by Hamid");
19 | Scene scene = new Scene(root);
20 | primaryStage.setScene(scene);
21 | scene.getStylesheets().add(getClass().getResource("main.css").toExternalForm());
22 | //done.setFont(new Font(20.0));
23 | primaryStage.show();
24 | }
25 |
26 |
27 | public static void main(String[] args) {
28 | launch(args);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/out/artifacts/File_Organizer/File_Organizer.jnlp:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Sample JavaFX Application
5 | Hamid Siddiqui
6 | Sample JavaFX 2.0 application.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Hamid Siddiqui
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/out/artifacts/File_Organizer/File_Organizer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
36 |
37 |
38 | Test page for File Organizer
39 | Webstart: click to launch this app as webstart
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/hamid/CustomFileVisitor.java:
--------------------------------------------------------------------------------
1 | package hamid;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.*;
5 | import java.nio.file.attribute.BasicFileAttributes;
6 | import java.util.Arrays;
7 | import java.util.HashSet;
8 |
9 | /**
10 | * Created by Hamid on 1/29/2016.
11 | */
12 |
13 | class CustomFileVisitor extends SimpleFileVisitor {
14 |
15 |
16 | private String extensions[] = null;
17 | private Path newFilePath;
18 | protected CustomFileVisitor(String source,String[] extensions,String folderName) {
19 | super();
20 | newFilePath = Paths.get(source,folderName);
21 | this.extensions = extensions;
22 | }
23 |
24 | @Override
25 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)throws IOException{
26 |
27 |
28 | String filename = file.getFileName().toString();
29 | int extensionpos = filename.lastIndexOf('.');
30 | String extension = filename.substring(extensionpos+1).toLowerCase();
31 | if(Files.notExists(newFilePath))
32 | Files.createDirectories(newFilePath);
33 | if(extensions==null)
34 | System.out.println("No extensions");
35 | for(String ex: extensions) {
36 | if(ex.equals(extension))
37 | try {
38 | Files.move(file, newFilePath.resolve(filename));
39 | }
40 | catch(IOException e) {
41 | System.out.println("File not moved "+ file);
42 | System.out.println("Error "+ e.getMessage());
43 | System.out.println("Cause of not moving "+ e.getCause());
44 | }
45 | }
46 |
47 | return FileVisitResult.CONTINUE;
48 | }
49 |
50 | @Override
51 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
52 | System.out.println("Directory visiting " + dir);
53 | return FileVisitResult.CONTINUE;
54 | }
55 |
56 | @Override
57 | public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
58 | System.out.println("File visit failed" + file);
59 | return FileVisitResult.CONTINUE;
60 | }
61 |
62 | @Override
63 | public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
64 | System.out.println("Directory finish " + dir);
65 | return FileVisitResult.CONTINUE;
66 | }
67 | }
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/src/hamid/main.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
18 |
22 |
23 |
27 |
34 |
40 |
45 |
51 |
56 |
60 |
65 |
69 |
--------------------------------------------------------------------------------
/out/production/File Organizer/hamid/main.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
18 |
22 |
23 |
27 |
34 |
40 |
45 |
51 |
56 |
60 |
65 |
69 |
--------------------------------------------------------------------------------
/src/hamid/Controller.java:
--------------------------------------------------------------------------------
1 | package hamid;
2 |
3 | import javafx.event.ActionEvent;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.CheckBox;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.control.TextField;
8 | import javafx.scene.text.Text;
9 | import javafx.stage.DirectoryChooser;
10 | import javafx.stage.Stage;
11 |
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.nio.file.*;
15 | import java.nio.file.attribute.BasicFileAttributes;
16 | import java.util.Arrays;
17 | import java.util.EnumSet;
18 | import java.util.HashSet;
19 |
20 | public class Controller {
21 |
22 | @FXML private Text selectFile;
23 | @FXML private Text done;
24 | @FXML private CheckBox checkBoxCustom;
25 | @FXML private TextField customFolderName;
26 | @FXML private TextField customExtension;
27 | @FXML private Label customFolderNameLabel;
28 | @FXML private Label customExtensionLabel;
29 |
30 | static private boolean DEFAULT = true;
31 |
32 | public void initialize(){
33 | selectFile.setText(System.getProperty("user.dir"));
34 |
35 | }
36 |
37 | @FXML
38 | protected void handleFileChooserButtonAction(ActionEvent event) {
39 | done.setText("");
40 | DirectoryChooser chooser = new DirectoryChooser();
41 | chooser.setInitialDirectory(new File(selectFile.getText()));
42 | chooser.setTitle("Select Folder");
43 | File file = chooser.showDialog(new Stage());
44 | selectFile.setText(file.toString());
45 | }
46 | @FXML protected void handleCustomCheckBoxAction(ActionEvent event){
47 |
48 | if (checkBoxCustom.isSelected()) {
49 | customFolderName.setVisible(true);
50 | customExtension.setVisible(true);
51 | customExtensionLabel.setVisible(true);
52 | customFolderNameLabel.setVisible(true);
53 | DEFAULT = false;
54 |
55 | } else {
56 | customFolderName.setVisible(false);
57 | customExtension.setVisible(false);
58 | customExtensionLabel.setVisible(false);
59 | customFolderNameLabel.setVisible(false);
60 | DEFAULT=true;
61 | }
62 | done.setText("");
63 |
64 | }
65 | @FXML
66 | protected void handleOrganizeButton(ActionEvent event)throws IOException {
67 | selectFile.setDisable(true);
68 |
69 | String current = selectFile.getText(); //"E:\\Download old";//System.getProperty("user.dir");
70 |
71 | System.out.println("Processing Files");
72 | if(!DEFAULT && !customExtension.getText().equals("") && !customFolderName.getText().equals(""))
73 | { done.setText("Processing..");
74 | Files.walkFileTree(Paths.get(current), EnumSet.noneOf(FileVisitOption.class), 1, new CustomFileVisitor(current, customExtension.getText().toLowerCase().split(","),customFolderName.getText()));
75 | done.setText("Done!");
76 | }
77 | else
78 | if(!DEFAULT && (customExtension.getText().equals("")||customFolderName.getText().equals("")))
79 | done.setText("Folder Name or Extension is empty.\nUncheck Custom option for default.");
80 | else
81 | { done.setText("Processing..");
82 | Files.walkFileTree(Paths.get(current), EnumSet.noneOf(FileVisitOption.class), 1, new DefaultFileVisitor(current));
83 | done.setText("Done!");
84 | }
85 | selectFile.setDisable(false);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/hamid/DefaultFileVisitor.java:
--------------------------------------------------------------------------------
1 | package hamid;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.*;
5 | import java.nio.file.attribute.BasicFileAttributes;
6 | import java.util.Arrays;
7 | import java.util.HashSet;
8 |
9 | /**
10 | * Created by Hamid on 1/29/2016.
11 | */
12 |
13 | class DefaultFileVisitor extends SimpleFileVisitor {
14 |
15 | static final String audio_formats[] = {"mp3","aac","flac","ogg","wma","m4a","aiff"};
16 | static final String image_formats[] = {"png","jpeg","jpg","gif","bmp","svg","webp","fig"};
17 | static final String doc_formats[] = {"pdf","doc","docx","xls","xlsv","ppt","pptx","ppsx","xlsx"};
18 | static final String archive_formats[] = {"zip","rar","7z","tar","gz","bz2","iso","dmg"};
19 | static final String video_formats[] = {"flv","ogg","ogv","avi","mov","qt","wmv","mp4","mpg","mpeg","3gp","mkv","webm"};
20 |
21 | static final HashSet images = new HashSet(Arrays.asList(image_formats));
22 | static final HashSet audio = new HashSet(Arrays.asList(audio_formats));
23 | static final HashSet docs = new HashSet(Arrays.asList(doc_formats));
24 | static final HashSet archives = new HashSet(Arrays.asList(archive_formats));
25 | static final HashSet videos = new HashSet(Arrays.asList(video_formats));
26 | final Path audioPath,docsPath,imagesPath,archivesPath,videosPath;
27 | String source=null;
28 | protected DefaultFileVisitor(String source) {
29 | super();
30 | this.source = source;
31 | audioPath = Paths.get(source, "Music");
32 | docsPath = Paths.get(source,"Documents");
33 | imagesPath = Paths.get(source,"Pictures");
34 | archivesPath = Paths.get(source,"Archives");
35 | videosPath = Paths.get(source,"Videos");
36 | createDirs();
37 | }
38 | private void createDirs(){
39 | try {
40 | if (Files.notExists(audioPath))
41 | Files.createDirectories(audioPath);
42 | if (Files.notExists(docsPath))
43 | Files.createDirectories(docsPath);
44 | if (Files.notExists(imagesPath))
45 | Files.createDirectories(imagesPath);
46 | if (Files.notExists(archivesPath))
47 | Files.createDirectories(archivesPath);
48 | if (Files.notExists(videosPath))
49 | Files.createDirectories(videosPath);
50 | }
51 | catch(IOException e)
52 | {
53 | System.out.println("Directory cannot be created "+e.getMessage());
54 | }
55 | }
56 |
57 | @Override
58 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs){
59 |
60 |
61 | String filename = file.getFileName().toString();
62 | int extensionpos = filename.lastIndexOf('.');
63 | String extension = filename.substring(extensionpos+1).toLowerCase();
64 | try {
65 | if (images.contains(extension))
66 | {
67 | Files.move(file, Paths.get(imagesPath.toString(), filename));
68 | }
69 | else if (audio.contains(extension))
70 | {
71 | Files.move(file, Paths.get(audioPath.toString(), filename));
72 | }
73 | else if (docs.contains(extension))
74 | {
75 | Files.move(file, Paths.get(docsPath.toString(), filename));
76 | }
77 | else if (archives.contains(extension))
78 | {
79 | Files.move(file, Paths.get(archivesPath.toString(), filename));
80 | }
81 | else if (videos.contains(extension))
82 | {
83 | Files.move(file, Paths.get(videosPath.toString(), filename),StandardCopyOption.REPLACE_EXISTING);
84 | }
85 | }
86 | catch(IOException e){
87 | System.out.println("File not moved "+ e.getMessage());
88 | System.out.println("File not moving cause "+ e.getCause());
89 | }
90 |
91 |
92 |
93 | return FileVisitResult.CONTINUE;
94 | }
95 |
96 | @Override
97 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
98 | System.out.println("Directory visiting " + dir);
99 | return FileVisitResult.CONTINUE;
100 | }
101 |
102 | @Override
103 | public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
104 | System.out.println("File visit failed" + file);
105 | return FileVisitResult.CONTINUE;
106 | }
107 |
108 | @Override
109 | public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
110 | System.out.println("Directory finish " + dir);
111 | return FileVisitResult.CONTINUE;
112 | }
113 | }
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------