Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: I need to get files with different timespan 1hr, 1day.1 week Date: Fri, 1 Jun 2018 07:43:55 -0400 Organization: A noiseless patient Spider Lines: 117 Message-ID: References: <6ba6236b-78bd-4224-a7be-a0dcb28e1a9a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 1 Jun 2018 11:43:57 -0000 (UTC) Injection-Info: h2725194.stratoserver.net; posting-host="b1b2cee7e5f0a70014baae377ecdd9e1"; logging-data="26743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185MYC2R/Z1wrJ/XbYq2qaH" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:i837kUSuaJC+ywlbsRH4ZbZ6YUA= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:38326 On 6/1/2018 1:08 AM, msr2858@gmail.com wrote: > > Problem: > iam able to get one day files but i didnt get one hour and one week files could you please help me It might help if you explained exactly what "one hour files" and "one week files" are. Hint, hint. > package hellomongo; > > import java.io.File; > import java.text.SimpleDateFormat; > import java.util.Date; > > public class FDate { > String stringToday1; > String path; > String base="/home/msr/hike/"; > > public void getdayfilnames() { > Date today1 = new Date(); > System.out.println("today1 :: " + today1); > // let us convert different formats of today1 into strings > SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy"); > stringToday1 = sdf1.format(today1); > System.out.println("today1 :: " + stringToday1); > > path=base+stringToday1; > System.out.println("dayysss:"+ path); I observe that this statement could not possibly produce the output you claim (below). I therefore conclude that your report of "Here's what I did and here's what happened" is incorrect. > File folder = new File(path); > File[] listOfFiles = folder.listFiles(); > > > for (int i = 0; i < listOfFiles.length; i++) { > if (listOfFiles[i].isFile()) { > String fname=listOfFiles[i].getName(); > > > > System.out.print(" "+fname+" "); Same remark: This statement could not possibly have produced the output you reported. You are lying to us -- perhaps innocently, but you are lying nonetheless. > } > > > /*if (listOfFiles[i].isFile()) { > String fname=listOfFiles[i].getName(); > System.out.println(" fname :"+fname); > String dayfile=fname.substring(1, 10); > if(day==dayfile) { > System.out.println(fname); > } > } */ > } > > > } > } > package hellomongo; > > import java.io.File; > import java.io.FilenameFilter; > import java.text.DateFormat; > import java.text.ParseException; > import java.text.SimpleDateFormat; > import java.util.Date; > > public class Timedate { > > public static void main(String[] args) > { > > Timedate td=new Timedate(); Why bother with this? It burns a few CPU cycles, chews up a little bit of memory, and accomplishes nothing useful. > FDate fd=new FDate(); > fd.getdayfilnames(); > > } > } > Output for oneday files: ... except this is not the actual output, not from the code you've shown at any rate. > dayysss:/home/msr/hike/31-05-2018: > 31-05-2018_10-42-25_rakesh_hike_load_608_output.txt > 31-05-2018_10-42-38_rakesh_hike_cpu_bd7_output.txt > 31-05-2018_10-42-46_rakesh_hike_ram_d8c_output.txt Others may (or may not) be more patient with you, but I for one will offer no further help until: 1) You define *precisely* what is meant by "one day files", "one hour files" and "one week files," 2) You explain in more detail where the various files reside and in what folders, 3) You exhibit code and output (or error messages) that *match*. -- esosman@comcast-dot-net.invalid Nine hundred sixty-four days to go.