Click here to Skip to main content
14,454,493 members
   

Java

 
QuestionRe: Sigar API Pin
Richard MacCutchan21-Jan-18 22:59
communityengineerRichard MacCutchan21-Jan-18 22:59 
AnswerRe: Sigar API Pin
Member 1363596722-Jan-18 18:24
MemberMember 1363596722-Jan-18 18:24 
GeneralRe: Sigar API Pin
Richard MacCutchan22-Jan-18 22:36
communityengineerRichard MacCutchan22-Jan-18 22:36 
GeneralRe: Sigar API Pin
Member 1363596722-Jan-18 22:37
MemberMember 1363596722-Jan-18 22:37 
QuestionFind and query files in a directory in date format yyymmdd Pin
hm916-Jan-18 23:45
Memberhm916-Jan-18 23:45 
AnswerRe: Find and query files in a directory in date format yyymmdd Pin
jschell17-Jan-18 15:29
Memberjschell17-Jan-18 15:29 
AnswerRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan17-Jan-18 22:56
communityengineerRichard MacCutchan17-Jan-18 22:56 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
hm918-Jan-18 0:13
Memberhm918-Jan-18 0:13 
Thanks for the suggestions.
I made a start now by listing all the files with the extension .log and it works.
since the files are in yyyymmdd.log format, i only want to list the last one - 1. then copy it to another file called logged.log for instance. Could you please help achieve this with the code below?. The code below navigate to the directory and list all files with the extension .log. The printed output is:

20180118.Log
20180117.Log
20180116.Log


So I am interested in the second one: 20180117.Log


import java.util.List;
import java.io.File;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.regex.Pattern;


class search
{
public static void main(String[] args) {

    String WILD_CARD = "";
     List <File> fileList = new LinkedList<File>();
       File folder = new File("d:\\");
       File[] listOfFiles = folder.listFiles();
        if(WILD_CARD!=null) {  
            Pattern wildCardPattern = Pattern.compile(".*"+WILD_CARD+"(.*)?.log",Pattern.CASE_INSENSITIVE);
            for(File file: listOfFiles) {
                java.util.regex.Matcher match = wildCardPattern.matcher(file.getName());
                while(match.find()){
                    String fileMatch = match.group();
                    if(file.getName().equals(fileMatch))  {
                        fileList.add(file); // doesn't work
                    }
                }
            }
        }
        else
            fileList = new LinkedList<File>( Arrays.asList(folder.listFiles()));

        for (File f: fileList) System.out.println(f.getName());
}

}

GeneralRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan18-Jan-18 0:16
communityengineerRichard MacCutchan18-Jan-18 0:16 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
hm918-Jan-18 0:29
Memberhm918-Jan-18 0:29 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan18-Jan-18 0:32
communityengineerRichard MacCutchan18-Jan-18 0:32 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
hm918-Jan-18 0:59
Memberhm918-Jan-18 0:59 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan18-Jan-18 1:32
communityengineerRichard MacCutchan18-Jan-18 1:32 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
hm918-Jan-18 2:29
Memberhm918-Jan-18 2:29 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan18-Jan-18 2:45
communityengineerRichard MacCutchan18-Jan-18 2:45 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
hm918-Jan-18 2:55
Memberhm918-Jan-18 2:55 
GeneralRe: Find and query files in a directory in date format yyymmdd Pin
Richard MacCutchan18-Jan-18 3:54
communityengineerRichard MacCutchan18-Jan-18 3:54 
QuestionWhat is wrong with this java code, why is it not printing Factorial? Pin
Member 1362428615-Jan-18 11:02
MemberMember 1362428615-Jan-18 11:02 
AnswerRe: What is wrong with this java code, why is it not printing Fibonacci? Pin
Richard MacCutchan15-Jan-18 22:45
communityengineerRichard MacCutchan15-Jan-18 22:45 
GeneralRe: What is wrong with this java code, why is it not printing Fibonacci? Pin
Member 1362428616-Jan-18 3:07
MemberMember 1362428616-Jan-18 3:07 
GeneralRe: What is wrong with this java code, why is it not printing Fibonacci? Pin
Richard Deeming16-Jan-18 4:07
communityengineerRichard Deeming16-Jan-18 4:07 
AnswerRe: What is wrong with this java code, why is it not printing Factorial? Pin
vishaljamdagni29-Jan-18 19:58
professionalvishaljamdagni29-Jan-18 19:58 
QuestionJava Array Out Of Bound Issue Pin
Akshit Gupta13-Jan-18 6:50
MemberAkshit Gupta13-Jan-18 6:50 
AnswerRe: Java Array Out Of Bound Issue Pin
phil.o13-Jan-18 7:20
mvephil.o13-Jan-18 7:20 
QuestionRemove All Items in nested HashMap Pin
Member 1354659210-Jan-18 10:12
MemberMember 1354659210-Jan-18 10:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.