Restored from previous forum. Originally posted by PB.
Anyone know how to set a file's date stamp (all three, ie. created,
modified, and accessed)? I'd want to do this based on a random date
from say 1970 to 2002, and here's why:
I want to view the MP3 files in my folder in a very random fashion.
Sorting by size seemed to be a good idea at the time, but then I
realised all the long songs were bunched together, which I didn't
want. Sorting by date also fails because it places together all the
songs that I ripped from my CDs. I guess what I need is an app that
could set the filedate to something random, on each file, so that
sorting by date would give a very random listing... so does anyone
know of anything like this? Thanks.
PB - Registered PureBasic Coder
Setting a file's date stamp
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> Why not use Random() for that part, PB ??
I don't want to play them -- I want to view the files in their folder
in a random order. Could be for any files, not just MP3. And the only
way I can think of, to do it, is to randomize their date stamps, and
then sort by date.
I've since found this web page...
http://www.freevbcode.com/ShowCode.asp? ... NoBox=True
...but I haven't successfully converted it to PureBasic yet.
PB - Registered PureBasic Coder
> Why not use Random() for that part, PB ??
I don't want to play them -- I want to view the files in their folder
in a random order. Could be for any files, not just MP3. And the only
way I can think of, to do it, is to randomize their date stamps, and
then sort by date.
I've since found this web page...
http://www.freevbcode.com/ShowCode.asp? ... NoBox=True
...but I haven't successfully converted it to PureBasic yet.
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
(just quick and dirty, haven't tested it. Just for showing an algo suggestion)
* note: i'm a little uncertain about the use of usefile() in the api function, should work but if it doesn't do it like this instead:
Can't you just do this for every file in the directory:Originally posted by PB
> Why not use Random() for that part, PB ??
I don't want to play them -- I want to view the files in their folder
in a random order. Could be for any files, not just MP3. And the only
way I can think of, to do it, is to randomize their date stamps, and
then sort by date.
(just quick and dirty, haven't tested it. Just for showing an algo suggestion)
Code: Select all
Procedure ChangeDate(filename.s)
if openfile(0, filename)
time.FILETIME\dwHighDateTime = random($ffff)
timeL\dwLowDateTime = random($ffffffff)
SetFileTime_(usefile(0), @time, 0, 0) ; just sets the creation time
Closefile(0)
endif
endprocedure
Code: Select all
hfile.l = openfile(...)
if hfile
...
setfiletime_(hfile, ...)
endif
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
UPDATE: Thanks Pupil! Due to your code and some other values I found
on the net, the following code works just like I wanted. I can now view
files by date and they are shown in "random" order.
And why did I want this ability? Because I have 1200 MP3 files that
I want to backup to CD-ROM, but in random order, so disc 1 holds a
random selection of them, as does disc 2, etc. There was absolutely
no other way I knew of to achieve this task, but PureBasic saved the
day yet again!
PB - Registered PureBasic Coder
UPDATE: Thanks Pupil! Due to your code and some other values I found
on the net, the following code works just like I wanted. I can now view
files by date and they are shown in "random" order.
And why did I want this ability? Because I have 1200 MP3 files that
I want to backup to CD-ROM, but in random order, so disc 1 holds a
random selection of them, as does disc 2, etc. There was absolutely
no other way I knew of to achieve this task, but PureBasic saved the
day yet again!
Code: Select all
; Example assumes 3 x MP3s exist in current folder (1.mp3, 2.mp3, 3.mp3).
;
For r=1 To 3
rantime.FILETIME
;GetSystemTimeAsFileTime_(rantime) ; Set "modified" to current time.
rantime\dwHighDateTime=Random(999999)+29502071 ; Wish I knew the real range!
rantime\dwLowDateTime=Random(999999)+2682590433 ; Wish I knew the real range!
f$=Str(r)+".mp3"
Debug f$
f=CreateFile_(f$,#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)
If f0
Debug SetFileTime_(f,0,0,rantime)
CloseHandle_(f)
EndIf
Next
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm