Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetFilesInFolder , sort on size and date
#1
Macro Macro6
Code:
Copy      Help
int i
ARRAY(str) a
str folder="e:\test"
GetFilesInFolder a folder "" 2 1 ;; getprop 1 = size (3=time created)
for i 0 a.len
,out a[i]

How can you sort on filesize and date using ARRAY a?


EDIT: I found out (I think) , and sorry for the wrong path in "str folder" I corrected it.

I have put the explanation in green code, but I do not know if it is correct:

Macro Macro2
Code:
Copy      Help
ARRAY(str) a
str folder="e:\test"
GetFilesInFolder a folder "" 2 1 ;; last number: 1 = size / 3 = time created
int i

;a[] contains paths like this

;45624 e:\test\file2.txt
;124 e:\test\file2.txt
;1940 e:\test\file3.doc
;130 e:\test\file4.doc

;You can now sort array becuase each item in array begins with integer value
;To output the PATH only, use the following in for loop (i=counter in 'for-loop').
;long t=val(a[i] 1 _i)   =>   it seems to extract the INTEGER value only.
;To output the path only, put the NUMERIC-part (integer value) in a string container with the command:
;_s=t
;Then the following command only outputs the path
;str sPath=a[i]+_s.len+1

;It seems the number after the a[i] =>  a[i]+[NUMBER] is the characterposition from where the
;actual path begins. The +1 just takes into account the empty space.

a.sort(8)

for i 0 a.len
,long t=val(a[i] 1) ;; Convert the NUMBER part only to long    ?
,_s=t
,str sPath=a[i]+_s.len+1 ;;a[i]+#  ,  # is character position number where PATH begins
,out sPath

What confuses me is in the example (when you press F1 in QM editor on the "GetFilesInFolder" function)
Or here:
Copy most recent file

You see:

Macro Macro2
Code:
Copy      Help
DateTime t=val(a[i] 1 _i)

The "_i" represents:
Quote:length - int variable that receives the number of characters from the beginning of s to the end of the part of s that contains the number. Receives 0 if s does not begin with a number or the number is too big.

Neither in the QM helpfile example as well as in the topic link, the container _i get's a value, it's always zero.
Also in my example but the code works... Is there something I missed.
Or when _i=0, the "val" function starts processing from the most left position of the provided string until it receivers a none-numeric character??
(That would explain that it works, but I could be totally off...)
#2
This works here.
Macro Macro2790
Code:
Copy      Help
int i
ARRAY(str) a
str folder="c:\test"
GetFilesInFolder a folder "" 2 1 ;; getprop 1 = size (3=time created)
a.sort(8)
for i 0 a.len
,long t=val(a[i] 1 _i)
,out _i ;;should not be 0
,str sPath=a[i]+_i+1
,out F"{t}, {sPath}"

Output:
3
164, c:\test\data.csv
3
252, c:\test\form.cs
4
3342, c:\test\test.cs
4
5632, c:\test\test1.exe
4
5632, c:\test\test2.exe
4
5632, c:\test\test3.exe
4
5632, c:\test\test4.exe
7
1175552, c:\test\se.qml
#3
Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)