how to get a file's modified date/time and size in bytes? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: how to get a file's modified date/time and size in bytes? (/showthread.php?tid=2724) |
how to get a file's modified date/time and size in bytes? - madscijr - 05-22-2024 Does anyone know how to do this in native QB64PE? It would be useful to get all the file attributes, but last modified date/time and size in bytes is what I'm looking for right now. Native QB64 would be best but I'll take whatever method is most reliable and cross-platform if possible. Any help much appreciated... RE: how to get a file's modified date/time and size in bytes? - mdijkens - 05-22-2024 Timestamps are only available via platform dependant API's (I do have code-samples for Win) Filesize is easiest via: Code: (Select All)
RE: how to get a file's modified date/time and size in bytes? - SpriggsySpriggs - 05-22-2024 I don't have my code handy right now but you need to look at the FILETIME structs in Win32 API. The functions that use that will be what you need. I used some of that for this FTP library on the old forums. Huge FTP Library for Windows (WinAPI) (alephc.xyz) RE: how to get a file's modified date/time and size in bytes? - madscijr - 05-22-2024 (05-22-2024, 11:35 AM)SpriggsySpriggs Wrote: I don't have my code handy right now but you need to look at the FILETIME structs in Win32 API. The functions that use that will be what you need.Thank you, sir. I'll give it a look when I'm back at my computer... RE: how to get a file's modified date/time and size in bytes? - euklides - 05-22-2024 Well, for a single file, you can use this... (Here the code do not test if the file exist !) Code: (Select All) FICO$ = "d:\temp\CATALOGUE_PEARL_AVRIL_SEPT_2024.pdf" RE: how to get a file's modified date/time and size in bytes? - SMcNeill - 05-22-2024 wmic DataFile where "Name='D:\\Path\\To\\myfile.txt'" get LastModified /VALUE RE: how to get a file's modified date/time and size in bytes? - madscijr - 05-22-2024 (05-22-2024, 02:29 PM)euklides Wrote: Well, for a single file, you can use this... Thanks, I will give that a try when at the computer! (05-22-2024, 02:37 PM)SMcNeill Wrote: wmic DataFile where "Name='D:\\Path\\To\\myfile.txt'" get LastModified /VALUEThanks - is this a command line thing? Can you show how to get that in a variable in a QB64PE program? RE: how to get a file's modified date/time and size in bytes? - SMcNeill - 05-22-2024 (05-22-2024, 03:05 PM)madscijr Wrote:(05-22-2024, 02:29 PM)euklides Wrote: Well, for a single file, you can use this... Code: (Select All)
You may get the results back in wide format, so you might want to strip spaces out, depending on your OS settings. RE: how to get a file's modified date/time and size in bytes? - SpriggsySpriggs - 05-22-2024 I guess I'm going to have to become the old geezer who complains that everyone is ruining hard drives with temp files constantly. RE: how to get a file's modified date/time and size in bytes? - madscijr - 05-22-2024 (05-22-2024, 05:04 PM)SpriggsySpriggs Wrote: I guess I'm going to have to become the old geezer who complains that everyone is ruining hard drives with temp files constantly.Ha! Well in this case I was looking to see if a file changed on disk, and only access it if it changed. I figured looking at the timestamp and size in bytes are a good way to tell. The problem with using this SHELL method that creates a file is, it requires at least 3 disk accesses:
Not too efficient. For a lot of cases that might not be a big deal, but for what I'm doing, it would slow things down a lot. We have a thread somewhere to suggest new commands for QB64PE, right? Where can I suggest adding some built-in cross-platform commands to get a file's date / size / attributes (& maybe update them as well)? |