|
Post by rich357 on Sept 8, 2009 1:12:01 GMT -5
Is there any way using the method below to simply transfer the file names to an array?
if Platform$ = "win32" then files #dir, "public\cards\*.jpg" else 'assume Mac OS or Linux files #dir, "public/docs/*.html" end if #dir dateformat("mmm dd, yyyy") while #dir hasAnswer() #dir nextFile$() print #dir name$() a$=name$() wend
|
|
|
Post by Janet on Sept 8, 2009 9:52:17 GMT -5
Use a counter and the files command the first time to count the number of valid files. Dim an array to that number. Reset the counter to zero. Use the files command a second time to store the valid files in the array.
cls ' set up a counter ct = 0 files #dir, "public\resources\AlphImages\alphabet*.PNG"
' loop through to count the number of valid files while #dir hasAnswer() #dir nextFile$() ' increase ct by 1 with each file found ct = ct + 1 wend ' now you know how many files are there print "found ";ct;" files" ' dim an array to ct dim fName$(ct) ' reset ct to 0 ct = 0 ' loop through the files again files #dir, "public\resources\AlphImages\alphabet*.PNG" while #dir hasAnswer() #dir nextFile$() ' increase ct by 1 with each file found ct = ct + 1 ' store the file in the array fName$(ct) = #dir name$() wend ' print the file names for i = 1 to ct print fName$(i) next i end
|
|
|
Post by rich357 on Sept 8, 2009 12:41:38 GMT -5
Thanks. Modified the code for my needs. As I know the number of files in the folder, I just skip that part.
dim fi$(60) a=0 if Platform$ = "win32" then files #dir, "public\cards\*.jpg" ' #dir dateformat("mmm dd, yyyy") while #dir hasAnswer() #dir nextFile$() a=a+1 fi$(a)=#dir name$() wend
for a=1 to 60 print fi$(a) next a
wait
|
|
|
Post by JackWebb on Sept 8, 2009 20:26:04 GMT -5
Use a counter and the files command the first time to count the number of valid files. Dim an array to that number. Reset the counter to zero. Use the files command a second time to store the valid files in the array. Hey Janet, Nice work but It's actually even easier than that. rowcount() gives you the number of files in a directory. cls files #dir, "public\*.*" ct = #dir rowcount() dim fname$(ct) for i = 1 to ct #dir nextFile$() fname$(i) = #dir name$() '-- store the file in the array print fname$(i) next i end
|
|
|
Post by Janet on Sept 8, 2009 22:14:47 GMT -5
Use a counter and the files command the first time to count the number of valid files. Dim an array to that number. Reset the counter to zero. Use the files command a second time to store the valid files in the array. Hey Janet, Nice work but It's actually even easier than that. rowcount() gives you the number of files in a directory. cls files #dir, "public\*.*" ct = #dir rowcount() dim fname$(ct) for i = 1 to ct #dir nextFile$() fname$(i) = #dir name$() '-- store the file in the array print fname$(i) next i end
Good call. But wouldn't you still have to do a preliminary look-see if only the jpg files were going to be stored?
|
|
|
Post by StefanPendl on Sept 9, 2009 4:00:46 GMT -5
Nice work but It's actually even easier than that. rowcount() gives you the number of files in a directory. ROWCOUNT() returns the number of rows in the FILES table, which includes child folders too. A folder containing 10 files and 5 folders will result in a row count of 15. How about a folder containing 300 folders and only one file of interest, do you really need 301 array items?
|
|
|
Post by JackWebb on Sept 9, 2009 6:05:19 GMT -5
ROWCOUNT() returns the number of rows in the FILES table, which includes child folders too. A folder containing 10 files and 5 folders will result in a row count of 15. How about a folder containing 300 folders and only one file of interest, do you really need 301 array items? Can you post some example code using ROWCOUNT() that would demonstrate the behavior you describe? Janet.. darn you're good! The answer is no you do not. Just change *.* to *.jpg and only the jpg file names will be returned. Oh look I got a promotion, I have 2 green stars now! ;D Jack cls files #dir, "public\*.jpg" ct = #dir rowcount() dim fname$(ct) for i = 1 to ct #dir nextFile$() fname$(i) = #dir name$() '-- store the file in the array print fname$(i) next i print chr$(13); ct; " files were found." end
|
|
|
Post by kokenge on Sept 9, 2009 7:19:15 GMT -5
And as long as we are doing directories, can anyone show me how to get a root directory on a windows OS of: files #dir, "C:\*.*" How do you get around the error message without doing a SPAN directory to a file and then reading the file.
Thanks for the help.. Dan
|
|