Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
05-22-2024, 03:25 AM
(This post was last modified: 05-22-2024, 03:26 AM by madscijr.)
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...
Posts: 128
Threads: 12
Joined: Apr 2022
Reputation:
14
Timestamps are only available via platform dependant API's (I do have code-samples for Win)
Filesize is easiest via:
Code: (Select All)
Open myfile$ for input access read as #99
filesize&&= lof(99)
close #99
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
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)
Tread on those who tread on you
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(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.
I used some of that for this FTP library on the old forums.
Huge FTP Library for Windows (WinAPI) (alephc.xyz) Thank you, sir. I'll give it a look when I'm back at my computer...
Posts: 55
Threads: 4
Joined: Apr 2022
Reputation:
5
05-22-2024, 02:29 PM
(This post was last modified: 05-22-2024, 02:40 PM by euklides.)
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"
GoSub INFOFIC
Print NAMEFIC$ + Chr$(10) + Str$(volufic#) + Chr$(10) + DATEFIC$ + Chr$(10) + TIMEFIC$
Sleep
End
'--------------------------------
'---SUB, go in with 'fico$' = full path+name of the file--informations given for one single ------
INFOFIC: Shell _Hide "cmd /c dir " + FICO$ + " /X > D0S-DATA.INF"
DATEFIC$ = "": canal = FreeFile: Open "D0S-DATA.INF" For Input As canal
While Not EOF(canal): Line Input #canal, i$:: i$ = _Trim$(i$)
If Mid$(i$, 3, 1) = "/" And Mid$(i$, 6, 1) = "/" Then
DATEFIC$ = Left$(i$, 10): i$ = _Trim$(Right$(i$, Len(i$) - 10))
TIMEFIC$ = Left$(i$, 5): Mid$(TIMEFIC$, 3, 1) = "h"
i$ = _Trim$(Right$(i$, Len(i$) - 5)): J = InStr(i$, " "): VoluFic$ = Left$(i$, J - 1): VoluFic1$ = ""
For u = 1 To Len(VoluFic$): V$ = Mid$(VoluFic$, u, 1): If InStr("0123456789", V$) > 0 Then VoluFic1$ = VoluFic1$ + V$
Next u: volufic# = Val(VoluFic1$): NAMEFIC$ = _Trim$(Right$(i$, Len(i$) - J))
End If
If DATEFIC$ <> "" Then GoTo finito
Wend
finito: Close canal: Kill "D0S-DATA.INF": Return
'-------------------------------------------
Why not yes ?
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
wmic DataFile where "Name='D:\\Path\\To\\myfile.txt'" get LastModified /VALUE
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
05-22-2024, 03:05 PM
(This post was last modified: 05-22-2024, 03:06 PM by madscijr.)
(05-22-2024, 02:29 PM)euklides Wrote: Well, for a single file, you can use this...
(Here the code do not test if the file exist !)
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 /VALUE Thanks - is this a command line thing? Can you show how to get that in a variable in a QB64PE program?
Posts: 2,698
Threads: 327
Joined: Apr 2022
Reputation:
217
(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...
(Here the code do not test if the file exist !)
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 /VALUE Thanks - is this a command line thing? Can you show how to get that in a variable in a QB64PE program?
Code: (Select All)
Shell "wmic DataFile where " + Chr$(34) + "Name='Z:\\foo.pdf'" + Chr$(34) + " get LastModified /VALUE > temp.txt"
_Delay .5
Open "temp.txt" For Input As #1
Do
Line Input #1, temp$
Print temp$
Loop Until EOF(1)
Close
You may get the results back in wide format, so you might want to strip spaces out, depending on your OS settings.
Posts: 734
Threads: 30
Joined: Apr 2022
Reputation:
43
I guess I'm going to have to become the old geezer who complains that everyone is ruining hard drives with temp files constantly.
Tread on those who tread on you
Posts: 733
Threads: 103
Joined: Apr 2022
Reputation:
14
(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:
- one to read the attributes
- one to write them to a temp file, and
- one to read that file
- (and another if we want to delete the temp file)
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)?
|