Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: I need to get files with different timespan 1hr, 1day.1 week Date: Fri, 1 Jun 2018 16:08:17 +0200 Organization: A noiseless patient Spider Lines: 63 Message-ID: References: <54a52822-55e3-4dea-9661-9f6cef3c4bf3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 1 Jun 2018 14:09:31 -0000 (UTC) Injection-Info: h2725194.stratoserver.net; posting-host="841dad2577e0b17a893f6e238bafe5ce"; logging-data="19380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+B1+JMP/ADmPbf/9zW8Ndn" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:F48S8RoOYRNdoULcXLGQbW/moUg= In-Reply-To: <54a52822-55e3-4dea-9661-9f6cef3c4bf3@googlegroups.com> X-Antivirus-Status: Clean Content-Language: en-GB X-Antivirus: AVG (VPS 180601-0, 06/01/2018), Outbound message Xref: csiph.com comp.lang.java.programmer:38330 On 2018-06-01 14:00, msr2858@gmail.com wrote: > On Thursday, May 31, 2018 at 3:37:14 PM UTC+5:30, siddared...@gmail.com wrote: >> i have a folder with different files with different dates i need to get if one hour file is there or not,need to display file name >> after that 1 day file need to displayed >> >> after 1 week file name should be displayed .. >> Ex: >> >> 31-05-2018 folder inside filename is like these : 31-05-2018_10-42-25_rakesh_hike_load_608_output.txt if i need to enter 1 day details i need to display that file > > in my home folder there are is one parent folder called Hike inside there are multiple folders with different dates as mentioned in below attached if i need to track one hour,one day,one week date folders i need to display files inside a folders .. need to display in files : > > Input: > Folder :28-05-2018: inside > FIles:28-05-2018_11-41-38_rakesh_hike_hc_393_output.txt > > > For one day time span it is working for me ..but one hour and one week its not working.. > Please try to collect your various postings into one -- USENET doesn't lend itself to chat. Compared to the code you posted, I would suggest: 1. That you parse both the date and the hour in the filename (you seemed to only parse the date); 2. That you use the objects from the java.time package (e.g. java.time.LocalDateTime) instead of the (essentially deprecated) java.util.Date; 3. That you put every file you find into a java.util.NavigableMap (e.g. TreeMap) with the LocalDateTime you parsed as the key and the File as the value; 4. Then, when you have built that map with all the files in your directory, you can search the map according to some input. Sample code (not compiled) for item #4: NavigableMap indexedFiles; LocalDateTime reference = ...; //Files in the hour of 'reference' LocalDateTime hourStart = reference.withMinute(0).withSecond(0).withNanos(0); LocalDateTime hourEnd = hourStart.plusHours(1); System.err.printf("Files in current hour (%s->%s):%n", hourStart, hourEnd); indexedFiles.subMap(hourStart, true, hourEnd, false).forEach( (time, file) -> System.err.println(file.getAbsolutePath()) ); //Files in the day of 'reference' LocalDateTime dayStart = reference.truncatedTo(ChronoUnit.DAYS); LocalDateTime dayEnd = dayStart.plusDays(1); System.err.printf("Files in current day (%s->%s):%n", dayStart, dayEnd); indexedFiles.subMap(dayStart, true, dayEnd, false).forEach( (time, file) -> System.err.println(file.getAbsolutePath()) ); //Files in the week of 'reference' is left as an exercise to the reader. //Cf. LocalDateTime#with(TemporalAdjuster) and TemporalAdjusters#previousOrSame et al. -- DF.