View Full Version : Function: File Count in a Directory
Intrigued
10-09-2005, 12:37 AM
-- This funciton will allow for the counting of all files in a directory (aka. folder)
function f_FileCount(dir)
tblFiles = File.Find(dir, "*.*", true, false, nil, nil)
if tblFiles ~= nil then
for i,v in tblFiles do
count = i
end
-- This is just one way to display the results
Dialog.Message("Directory file count...", "There are "..count.." files in that directory")
else
Dialog.Message("Directory file count...", "There are 0 files in that directory")
end
end
-- Example on how to use this function (also known as a "function call")
f_FileCount("AutoPlay\\Docs")
gogubooman
08-23-2006, 05:46 PM
If the folder has waay to many files....the response of the function will be slow...
My snippets folder...has around 13.300 files it took ~10 seconds to produce the result :)
RizlaUK
09-10-2006, 05:13 PM
nice function, right about the time on large dir, i just added a status dialog to it so it dosent give the hanging effect
eg:
StatusDlg.Show(MB_ICONNONE, false);
-- Example on how to use this function (also known as a "function call")
f_FileCount("C:\\")
StatusDlg.Hide();
scaned my whole c drive in 20 seconds, while displaying all files scaned
Intrigued
09-10-2006, 05:47 PM
Another version with a Cancel button this time:
-- This funciton will allow for the counting of all files in a directory (aka. folder)
function f_FileCount(dir)
StatusDlg.Show(MB_ICONNONE, false);
StatusDlg.ShowCancelButton(true, "Cancel")
tblFiles = File.Find(dir, "*.*", true, false, nil, nil)
if tblFiles ~= nil then
for i,v in tblFiles do
blnIsCancelled = StatusDlg.IsCancelled()
if blnIsCancelled ~= true then
count = i
else
blnQuit = true
break
end
end
StatusDlg.Hide()
if blnQuit ~= true then
-- This is just one way to display the results
Dialog.Message("Directory file count...", "There are "..count.." files in that directory")
end
blnQuit = false
end
end
-- Example on how to use this function (also known as a "function call")
f_FileCount("C:\\")
Stefan_M
10-12-2006, 06:02 AM
Another version with "Table.count" instead of a loop
function f_FileCount(dir)
local count=0;
tblFiles = File.Find(dir, "*.*", true, false, nil, nil)
if tblFiles ~= nil then
count = Table.count(tblFiles);
end;
return count;
end;
usage:
number_of_files=f_FileCount("C:\")
Stefan_M
latell
11-29-2006, 02:07 AM
Hi
Just made this one today.
it's a file list counter
put the whole path into the Directory Tab
and pressing Commence or Enter will do.
http://mfiles.naver.net/69bb5f8992c3a4123f56/data20/2006/11/29/261/flcv2-4316-terratan.exe
spider
10-02-2007, 10:50 PM
excuse me
can the files be arranged with filename ,or by CreationDate,or by WriteDate?
can some body give some ideas or example
excuse me
can the files be arranged with filename ,or by CreationDate,or by WriteDate?
can some body give some ideas or example
You can use File.GetAttributes and .CreationDateISO in loop then remove "-" from result of date and sync. each file with other.
RizlaUK
10-14-2007, 08:51 AM
You can use File.GetAttributes and .CreationDateISO in loop then remove "-" from result of date and sync. each file with other.
yup, used with "Table.Sort" should do the trick
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.