Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abraham-ny/filetool
File handler java library bringing the extra features that original Java Files package lacks.
https://github.com/abraham-ny/filetool
archive cross-platform file-engine file-handler jar java-library java-library-starter library no-gui
Last synced: about 2 months ago
JSON representation
File handler java library bringing the extra features that original Java Files package lacks.
- Host: GitHub
- URL: https://github.com/abraham-ny/filetool
- Owner: abraham-ny
- License: apache-2.0
- Created: 2024-01-07T13:18:11.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-07T13:24:16.000Z (12 months ago)
- Last Synced: 2024-11-10T10:40:30.033Z (about 2 months ago)
- Topics: archive, cross-platform, file-engine, file-handler, jar, java-library, java-library-starter, library, no-gui
- Language: Java
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# File Tool
**NB: Most of the code is PORTED from FileHandler(SWING GUI APP)**
***
Java Library to perform some extra file functions that are not implemented in the standard JDK.
Made using JDK 17 and **ANT** but can also work on **any JDK** .
Very lightweight, simple function calls and straight forward function names such as the ```removeWord()``` or ```getFileSize()``` functions in the ```FileTool``` class.
**No external dependencies required**
# Usage
## Classes
- FileMultiplier
- Generate multiple copies of a file given the file name.
```
//in this example I use a mail merging list of recipients
int numberOfCopies = recipientsList.length;
FileMultiplier mMultiplier;//no constructor needed
mMultiplier.multiply(file.getName(), recipientDir(), numberOfCopies);
//Done!
```
- FileOrganizer
- Organize files by moving them into folders based on the file extension
```
FileOrganizer org = new FileOrganizer();
String musicExtensions = (FileTool)ft.audex;
org.iterateAndFilter(downloadsDir, musicExtensions);//returns String[]
//or use loadF(same params)
//throws IOException so you catch it!
//use clearList() after iterateFilter before you run another iteration
org.clearList();//clear the String[]
```
- Move files from a dir to another.
```
org.moveFiles(originalFilePath(string), newPath(string));
```- Move a ***String[ ]*** of fileNames(files) to a new directory
```
//could not name moveFiles since ambiguous with above function
org.moveFi(destination(string), fileNameArr(String[]))
//throws IOException so catch or handle it!
```- FileRenamer
- Remove repeated word in file names from a common directory
```
FileRenamer rn = new FileRenamer();
String successStatus = rn.removeWordFromDir(dirName, wordToRemove, newWord /*or leave newWord AS EMPTY STRING to just remove word without replacing*/);
```- Remove repeated word from a list of files
```
//Similar to above but instead of folder path, accepts List
rn.removeWordFromList(listOfFiles, word, new);
```- FileTool
- Get file size in MB (MEGA bytes).
```
//returns STRING
String fileSize = FileTool.getFileSize(pathToFile(string))
``````
FileTool.print(String);
//simplified method for System.out.println(STRING);
//so you can just write shorter print statements.
```- Remove a word from a single file name
```
FileTool.removeWord(word, filePath(string));
// simple
```## Example Usage of Organizer
```
//process a folder to get what type of files are in it and how many (count) result as -> "Found 23 Documents...Videos...etc"
public void processDirAndFiles() {
// TODO add your handling code here:
orgState.setText("Wait...");
String fss1 = orgDestDir.getText();
if ("".equals(fss1)) {
orgDestDir.setText("You must select a folder to operate.");
} else {
orgBtn.setVisible(true);
orgState.setText("Processing files...");
String fss = "C:\\Users\\" + user + "\\Documents";//fss1 should be the value of dir text
//music
loadF(FileUtil.archex, fss1);
zips = fo.files;
orgDirInfo.setText("Found: " + zips.length + " archives.");
fo.clearList();
for (String sg : zips) {
System.out.println(sg);
}
orgProgBar.setValue(20);
fo.clearList();
//audio
loadF(FileUtil.audex, fss1);
auds = fo.files;
orgDirInfo.setText(orgDirInfo.getText() + "\n" + "Found: " + auds.length + " music.");
fo.clearList();
for (String sg : auds) {
System.out.println(sg);
}
orgProgBar.setValue(20 + orgProgBar.getValue());
fo.clearList();
//videos
loadF(FileUtil.videx, fss1);
vids = fo.files;
orgDirInfo.setText(orgDirInfo.getText() + "\n" + "Found: " + vids.length + " videos.");
fo.clearList();
for (String sg : vids) {
System.out.println(sg);
}
orgProgBar.setValue(20 + orgProgBar.getValue());
fo.clearList();
//pictures
loadF(FileUtil.picex, fss1);
pics = fo.files;
orgDirInfo.setText(orgDirInfo.getText() + "\n" + "Found: " + pics.length + " pictures.");
fo.clearList();
for (String sg : pics) {
System.out.println(sg);
}
orgProgBar.setValue(20 + orgProgBar.getValue());
fo.clearList();
//documents
loadF(FileUtil.docex, fss1);
docs = fo.files;
orgDirInfo.setText(orgDirInfo.getText() + "\n" + "Found: " + docs.length + " documents.");
fo.clearList();
for (String sg : docs) {
System.out.println(sg);
}
orgProgBar.setValue(20 + orgProgBar.getValue());
fo.clearList();
//apps
loadF(FileUtil.appex, fss1);
iapps = fo.files;
orgDirInfo.setText(orgDirInfo.getText() + "\n" + "Found: " + iapps.length + " executables.");
fo.clearList();
for (String sg : iapps) {
System.out.println(sg);
}
orgProgBar.setValue(10 + orgProgBar.getValue());
fo.clearList();
orgProgBar.setIndeterminate(false);
orgProgBar.setMaximum(100);
orgProgBar.setValue(100);
//dmg.setVisible(false);
}}
```After getting the dir file types info(optional), but useful to show to user you can now organize (enable the "Organize" button in your UI to allow user action) **Optional** but recommended
```
private void organizeBtnMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String fss = "C:\\Users\\" + user + "\\Music";
String o = orgDestDir.getText();
try {
fo.moveFi(uss.getDir("aar"), zips);
orgCmplete.setText("Moved: " + zips.length + " archives");
fo.moveFi(uss.getDir("mp4"), vids);
orgCmplete.setText(orgCmplete.getText() + "\nMoved: " + vids.length + " videos");
fo.moveFi(uss.getDir("mp3"), auds);
orgCmplete.setText(orgCmplete.getText() + "\nMoved: " + auds.length + " Music");
fo.moveFi(uss.getDir("doc"), docs);
orgCmplete.setText(orgCmplete.getText() + "\nMoved: " + docs.length + " Documents");
fo.moveFi(uss.getDir("app"), iapps);
orgCmplete.setText(orgCmplete.getText() + "\nMoved: " + iapps.length + " executables");
fo.moveFi(uss.getDir("pic"), pics);
orgCmplete.setText(orgCmplete.getText() + "\nMoved: " + pics.length + " pics");
//orgCmplete.setText("Success!");
} catch (IOException ex) {
orgCmplete.setText(ex.getMessage());
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
updateOldList(o);
}
```# TODO
- [ ] Add Zipping and Archiving features (zip, rar, jar, jad, gzip, 7z, tar...and more) if possible hence contributions are highly welcome
- [ ] Edit file meta-data such as Dates, Owner...and more.
### Contributing
Contributions are welcome, just clone the repo add your code then push and we'll check it out.
**Forks** are also welcome.## Users
Do you use this in your project(s)? we'd like to know or give us a mention.
- List Of Users
- No users yet.