CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Search for previous file in data format yyymmdd

  1. #1
    Join Date
    Jan 2018

    Search for previous file in data format yyymmdd


    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

    public static void main(String[] args) {
        File currentDir = new File("\\\\directory Path"); // current directory
    public static void displayDirectoryContents(File dir) {
        try {
            File[] files = dir.listFiles();
            for (File file : files) {
                System.out.println(" file:" + file.getCanonicalPath());
        } catch (IOException e) {

    thanks in advance
    Last edited by 2kaud; January 16th, 2018 at 10:46 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    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 '#']

    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 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++17 Compiler: Microsoft VS2019 (16.6.3)

  3. #3
    Join Date
    Jun 1999
    Eastern Florida

    Re: Search for previous file in data format yyymmdd


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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)