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.
-
1W7 has Powershell installed. I would suggest using that.– EBGreenJun 21, 2016 at 15:08
-
PowerShell was new to me, and if anyone else wants background: What is PowerShell, digitalcitizen.life/… , example of using it to count ftp files, salvoz.com/blog/2013/07/21/powershell-ftp-scripts– KAEJun 21, 2016 at 17:59
Add a comment
|
1 Answer
- Save remote file list to a file;
- Count number of lines in the file.
@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.
-
the question says "count the files in a directory", not "count the lines in a file" 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