Which version of DOS are you using, or what version of Windows is your command prompt running under? If running under Windows NT / 2000 / XP / 2003, then what you want to do is pretty easy, and can be done several different ways. To set the environment "numfiles" to contain the number of files in the current directory, you could run the following from within a batch file:
for /f %%a in ('dir /a^|find "File(s)"') do set numfiles=%%a