Eghbal
Eghbal

Reputation: 3803

Count number of files in a FTP folder

I use this code to see existed files in a specific folder from FTP :

ftp_client = ftp('IP','Username','Password');
aa = dir(ftp_client,'First_folder/Second_folder');

I can see file names with these codes :

aa(1,1).name
aa(2,1).name
aa(3,1).name
  1. How can I see all files names in a cell aray in this specific folder? Is there any command for it?

  2. How can I count number of existed files in this folder?

  3. How can I count number of existed files in this folder with a specific format?

Thanks.

Upvotes: 0

Views: 2091

Answers (1)

sco1
sco1

Reputation: 12214

  1. A simple way is to collect the values into the cell array by using curly brackets: filenames = {aa.name};

  2. The simplest method would be length(aa); or length(filenames);

  3. A couple ways. You can either refine your dir call, aa = dir(ftp_client,'First_folder/Second_folder/*.jpeg') for example, or use your own filter (regexp is one option) on your filenames to return the indices of what you want.

As a general aside, if you're utilizing this program on different operating systems, I would recommend utilizing fullfile (or filesep at the very least) to build your full pathnames to ensure the right separator is used. Though I didn't do it in my example above...

Upvotes: 1

Related Questions