Page 1 of 1

Posted: Tue Oct 08, 2002 2:57 am
by BackupUser
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

Posted: Tue Oct 08, 2002 3:34 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Why not use Random() for that part, PB ??

You have 3000 songs, so you do x = Random(2999)
and PlaySong(x+1).

cya,
...Danilo

(registered PureBasic user)

Posted: Tue Oct 08, 2002 4:43 am
by BackupUser
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

Posted: Tue Oct 08, 2002 10:35 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.
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.
Can't you just do this for every file in the directory:
(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
* 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:

Code: Select all

hfile.l = openfile(...)
if hfile
 ...
 setfiletime_(hfile, ...)
endif

Posted: Tue Oct 08, 2002 11:51 am
by BackupUser
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!

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
PB - Registered PureBasic Coder

Posted: Tue Oct 08, 2002 1:00 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Maybe the 64 bit resulting value of the random operation is lower than the lower date accepted by Windows? I read that the number specifies the number of 100-nanosecond intervals since January 1, 1601.

Just a thought. Bye,

El_Choni