-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FileFinder class for finding distinct filenames and existing files. #21
- Loading branch information
1 parent
6b8ecd9
commit cc51c69
Showing
7 changed files
with
103 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.kasirgalabs.tilki.utils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
public class FileFinder { | ||
|
||
public static String generateFileName(String fileName) { | ||
File file = new File(fileName); | ||
if(!file.exists()) { | ||
return fileName; | ||
} | ||
|
||
String generatedFileName; | ||
for(int i = 0; i < 100; i++) { | ||
generatedFileName = i + "_" + fileName; | ||
if(!new File(generatedFileName).exists()) { | ||
return generatedFileName; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static ArrayList<String> findGeneratedFileNames(String fileName) { | ||
ArrayList<String> fileList = new ArrayList<>(); | ||
if(new File(fileName).exists()) { | ||
fileList.add(fileName); | ||
} | ||
|
||
String generatedFileName; | ||
for(int i = 0; i < 100; i++) { | ||
generatedFileName = i + "_" + fileName; | ||
if(new File(generatedFileName).exists()) { | ||
fileList.add(generatedFileName); | ||
} | ||
} | ||
return fileList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters