Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38330
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| 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 | <perk2r$itk$1@dont-email.me> (permalink) |
| References | <a8a31edc-333e-48fd-a7e0-34f38c9e0d5d@googlegroups.com> <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 |
Show key headers only | View raw
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<Temporal, File> 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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
I need to get files with different timespan 1hr, 1day.1 week siddareddy.moolam@gmail.com - 2018-05-31 03:07 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-31 07:47 -0400
Re: I need to get files with different timespan 1hr, 1day.1 week siddareddy.moolam@gmail.com - 2018-05-31 05:59 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week Eric Douglas <e.d.programmer@gmail.com> - 2018-05-31 06:52 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-31 15:53 +0200
Re: I need to get files with different timespan 1hr, 1day.1 week Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-31 10:08 -0400
Re: I need to get files with different timespan 1hr, 1day.1 week msr2858@gmail.com - 2018-05-31 22:02 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week msr2858@gmail.com - 2018-05-31 22:08 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-06-01 07:43 -0400
Re: I need to get files with different timespan 1hr, 1day.1 week msr2858@gmail.com - 2018-06-01 04:57 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week msr2858@gmail.com - 2018-06-01 04:58 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week msr2858@gmail.com - 2018-06-01 05:00 -0700
Re: I need to get files with different timespan 1hr, 1day.1 week Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-06-01 16:08 +0200
csiph-web