-
January 16th, 2018, 10:37 AM
#1
Search for previous file in data format yyymmdd
Hi
I have a directory where log txt files are logged. Each log file has the following title date format 20180114.log, which is yyymmdd.
I want to search for data in the preceding file (date) so if the current date file is 20180114.log, I want to search the previous day 20180113.log, and then output the data i search for in anther text file.
How do I achieve this in java? any code examples I can follow?
I made a start by displaying the list of the files in the directory but could do with some help to achieve the above
Code:
public static void main(String[] args) {
File currentDir = new File("\\\\directory Path"); // current directory
displayDirectoryContents(currentDir);
}
public static void displayDirectoryContents(File dir) {
try {
File[] files = dir.listFiles();
for (File file : files) {
System.out.println(" file:" + file.getCanonicalPath());
}
} catch (IOException e) {
e.printStackTrace();
}
}
thanks in advance
Last edited by 2kaud; January 16th, 2018 at 10:46 AM.
Reason: Added code tags
-
January 16th, 2018, 10:46 AM
#2
Re: Search for previous file in data format yyymmdd
[When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#']
cheers!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 16th, 2018, 11:27 AM
#3
Re: Search for previous file in data format yyymmdd
Norm
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|