Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Guest

Very good Sir! Thank you very much for the quick reply.

Regards.
martin

Re: Enumerate Remote Files

.Where(file => file.IsDirectory || ((file.LastWriteTime.Date >= lastModifiedStartDate.Date) && (file.LastWriteTime.Date <= lastModifiedEndDate.Date)));
tonysut@gmail.com

Enumerate Remote Files

Hey guys. Awesome product.
I'm using this in C# to pull down files from a remote ftp on a daily basis.
My question is this, when enumerating the remote folder, subfolders and files, i'm having an issue where the results don't always include the folder names. (I.e. having iSDirectory set)

For example, when the
 lastModifiedEndDate = DateTime.Now.AddDay(0)
everything works as expected. I can loop through the results and using .IsDirectory see which entries are directories and which ones are files.

However, using anything other than 0 (today), it will return files, but not directory names.
For example
 lastModifiedEndDate = DateTime.Now.AddDay(-1) (Today minus 1 day)
folder names are excluded.

I suspect this is because, as new files get added to these directories everyday, the folder will always have a timestamp for the current day and that is why they do not get included in the result set when filtering on older date ranges.

I hope this makes sense. I need to pull back subfolder names every time regardless of date filtering.
I don't want to exclude the folder names from my results, just exclude them from the date filtering.

EnumerationOptions eOptions = EnumerationOptions.AllDirectories | EnumerationOptions.EnumerateDirectories;


fileInfos = session.EnumerateRemoteFiles(argsSettings.filePaths.remoteFolder, null, eOptions).Where(file => ((file.LastWriteTime.Date >= lastModifiedStartDate.Date) && (file.LastWriteTime.Date <= lastModifiedEndDate.Date)));


Thanks,
Tony