!! File Count Function Needed !!
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

!! File Count Function Needed !!

Started by ??????Hawk??????, 20 April, 2004, 22:03:46

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

??????Hawk??????

Heya Peeps.  Hope someone can help me out ..

im wanting a function to return all file names in a specified directory..

something like this:-

Function ReadFiles()
directory = "/files"
filename = "/r/n"
number = count files          // count the number of files in ' directory ' 
Loop                                  // loop 1 to number
get next filename           
filename = fileName.."/r/n"
end                                   // end loop
return FileName , number
end                             // end function



Thanks in Advance  ??????Hawk??????

NotRabidWombat

#1
function CountFiles(sDirectory)
   local sFileName = tmpname ();

   system("dir /b /a-d \""..sDirectory.."\" | find /c /v \"\" > \""..sFileName.."\"");
   local hFile = openfile (sFileName, "r");

   local iCount = read(hFile, "*n");

   closefile(sFileName);

   remove(sFileName);
end
Nothing to test on here. Hope it works, or you understand what I was going for.

Hrm, actually looks like you want a listing of files?

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

??????Hawk??????

yes m8  .  it is a listing of  files  that im after..

thx  anyway

NotRabidWombat

#3
Alrighty, in that case.
function ReadFiles(sDirectory)
   local sFileName = tmpname ();
   local sLine = nil;

   system("dir /b /a-d \""..sDirectory.."\" > \""..sFileName.."\"");
   local hFile = openfile (sFileName, "r");

   sLine = read(hFile, "*l");
   while ( sLine )
      -- sLine will be the file name in sDirectory
      sLine = read(hFile, "*l");
   end

   closefile(sFileName);

   remove(sFileName);
end

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

??????Hawk??????

not having any joy with that function m8  :-(

NotRabidWombat

Sorry. Right now I'm using the Wombot interpreter to check syntax ;-)

I'll be back home in an hour at which point I can debug.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

??????Hawk??????

#6
hi m8 thx

 i appreciate your help  ..  theres  no rush as ive closed my script boxes down for the evening..

but i would appreciate it if you could come up with something that followed this pattern returning the info required..


Function ReadFiles()
directory = "/files"
filename = "/r/n"
number = count files          // count the number of files in ' directory ' 
Loop                                  // loop 1 to number
get next filename           
filename = fileName.."/r/n"
end                                   // end loop
return FileName , number
end                             // end function

cheers  ??????Hawk??????

plop

i bet system is c++.
changed it 2 execute and added a do.
function ReadFiles(sDirectory)
   local sFileName = tmpname ();
   local sLine = nil;

   execute("dir /b /a-d \""..sDirectory.."\" > \""..sFileName.."\"");
   local hFile = openfile (sFileName, "r");

   sLine = read(hFile, "*l");
   while ( sLine ) do
      -- sLine will be the file name in sDirectory
      sLine = read(hFile, "*l");
   end

   closefile(sFileName);

   remove(sFileName);
end
plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

NotRabidWombat

Heh! :D It has been a while since I've used lua.

Yes system is c/c++.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

??????Hawk??????

#9
hi guys ..   thx for your help .  

the function works but  i get this error:-

Syntax error: bad argument #1 to `closefile' (invalid file handle)
stack traceback:

and the tmp.$$$   file is left in the scripts directory.
it makes a new tmp2.$$$  /  tmp3.$$$  and so on every time its executed.

SMF spam blocked by CleanTalk