1

When I use the Windows ftp command at the command window which I think is the DOS ftp command, is there a way to count the number of files in the remote directory? That way I can check that I ftp'ed them all. I am stuck using Window 7 built-in commands and can't use a different program.

2

1 Answer 1

1
@echo off

echo open ftp.example.com>ftp.txt
echo user>>ftp.txt
echo password>>ftp.txt
echo ls /remote/path files.txt>>ftp.txt
echo bye>>ftp.txt

ftp -s:ftp.txt

set /a LINES=0
for /f %%j in ('type files.txt^|find "" /v /c ') do set /a LINES=%%j

del files.txt
del ftp.txt

echo Number of files: %LINES%

As others have commented, using PowerShell script would be more elegant and reliable though.

2
  • the question says "count the files in a directory", not "count the lines in a file"
    – ashleedawg
    Oct 5, 2020 at 23:45
  • @ashleedawg Sure. And the answer shows how to do that by saving the file list to a file and counting the lines in the file. It wouldn't be the accepted answer, if it did not answer the question. If you have a better way how to count the files in a batch file, please post your own answer. Oct 6, 2020 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .