How to List Directory Contents with FTP in C#?

Try this: FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(uri); ftpRequest.Credentials =new NetworkCredential(“anonymous”,”janeDoe@contoso.com”); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory; FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); List<string> directories = new List<string>(); string line = streamReader.ReadLine(); while (!string.IsNullOrEmpty(line)) { directories.Add(line); line = streamReader.ReadLine(); } streamReader.Close(); It gave me a list of directories… all listed in the directories string list… tell me …

Read more

Getting a list of folders in a directory

I’ve found this more useful and easy to use: Dir.chdir(‘/destination_directory’) Dir.glob(‘*’).select {|f| File.directory? f} it gets all folders in the current directory, excluded . and … To recurse folders simply use ** in place of *. The Dir.glob line can also be passed to Dir.chdir as a block: Dir.chdir(‘/destination directory’) do Dir.glob(‘*’).select { |f| File.directory? …

Read more

Non-alphanumeric list order from os.listdir()

You can use the builtin sorted function to sort the strings however you want. Based on what you describe, sorted(os.listdir(whatever_directory)) Alternatively, you can use the .sort method of a list: lst = os.listdir(whatever_directory) lst.sort() I think should do the trick. Note that the order that os.listdir gets the filenames is probably completely dependent on your …

Read more

How do you get a list of the names of all files present in a directory in Node.js?

You can use the fs.readdir or fs.readdirSync methods. fs is included in Node.js core, so there’s no need to install anything. fs.readdir const testFolder=”./tests/”; const fs = require(‘fs’); fs.readdir(testFolder, (err, files) => { files.forEach(file => { console.log(file); }); }); fs.readdirSync const testFolder=”./tests/”; const fs = require(‘fs’); fs.readdirSync(testFolder).forEach(file => { console.log(file); }); The difference between the …

Read more