• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

delete files from a directory if datetime stamp matches

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the below code and eventhough the file name and datetime stamp matches it does not delete the file.

Can anyone shed some light ?

Here's the results I got


deleteme.docx File modification date and time : 23-07-2012 07:55
23-07-2012 07:55File not deleted!


I know there should be a issue with my comparison here --> if ((sdf.format(d)).toString() == s)

it gets compiled with no data type errors

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mei Jones wrote:
I know there should be a issue with my comparison here --> if ((sdf.format(d)).toString() == s)



When comparing objects' states ("contents"), use equals(), not ==. This includes comparing Strings for equality. The == operator tests if two references have the same value (both point to the same object or both are null). The equals() method, if properly written, tells if two objects have equal "contents" by whatever equality semantics are defined for the class in question.

Also, you don't need the toString() there, since format() returns a String.

Also, if you're comparing dates, you should compare them as Dates, not as Strings.
 
Mei Jones
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,.. Yes it worked..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic