So … I had a therapy session. Messaging therapy. Yeah it’s not for me. I need to be able to speak with someone face to face, or audio or something. Just chatting over a messaging service is not what I had in mind when it comes to therapy options. Eh, it’s whatever. I’ll deal without the bullshit that is what was offered as a “free” plan. I’ll get over it. I’ll just find something else that will work for me, that actually works out well and will meet my needs better. I don’t blame the company or the person I spoke with briefly, but it’s just not for me it would seem. That’s okay though. I gave it a shot. Figured that’s the least I could do considering my mental health and everything that goes on. They just weren’t equiped with the kind of service I need I think. Maybe I don’t need therapy. Perhaps I can do without and I’ll be just fine. Yeah that’s a good idea. I can deal with life without the though process of a therapist seeking to help me. There’s nothing wrong with that. In a way...
Sometimes you want to be able to change the created date of a file. Don't ask me WHY you would ever need to do this, but well here's a way in Java.
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.time.*;
public class ChangeCreatedDate {
public static void main(String[] args) throws IOException {
if (args.length == 2) {
File file = new File(args[0]);
if (file.exists()) {
file.setLastModified(System.currentTimeMillis());
} else {
file.createNewFile();
}
}
LocalDate date = LocalDate.parse(args[1]);
LocalTime time = LocalTime.now();
Path file = Paths.get(args[0]);
FileTime fileTime = FileTime.fromMillis(getMillisecondsSince1970(date, time));
Files.setAttribute(file, "creationTime", fileTime);
}
public static long getMillisecondsSince1970(LocalDate date, LocalTime time) {
ZonedDateTime zonedDateTime = ZonedDateTime.of(
date,
time,
ZoneId.systemDefault());
return zonedDateTime.toInstant().toEpochMilli();
}
}
Looking back at it, I wonder why I didn't make it so you could update the time as well as the date. Interesting. I mean it would make sense to be able to update both the date AND time. But I didn't have that in this section of code. Oh well, I'm sure I'll change it someday.
I find it interesting that we're updating an attribute of the file. One would think it would be someplace else, or easier to access directly on the file object itself. But well, it's not. So that's just that.
Comments
Post a Comment