0

C#:

How can we Extract the files URL by going into subdirectory of each of the folder and get URL of all the file with .log or .txt extension ?? Eg.There is a URL "https://example.com/folder1" From this URL it goes under each one of the subfolder and return the URL of all txt,log file like

https://example.com/folder1/sub1/sub2/abc.log

https://example.com/folder1/sub1/sub2/ghs.log

https://example.com/folder1/sub1/eyu.txt

get return after inputing example URL("https://example.com/folder1") and store all these into list of string

string[] files = fileExtensions.SelectMany(f => Directory.GetFiles(url, f, SearchOption.AllDirectories)).ToArray(); 

I have tried this but it is not supported any other methods??

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Karmesh Duggar
  • 33
  • 1
  • 12
  • is "allow directory listing" on or off? is the server side code under your control, or opaque? what have you tried so far? – Cee McSharpface Jul 22 '22 at 10:27
  • @CeeMcSharpface Directory listing is on as i can see on the browser i am able to extract data directly from URL of a single file but not able to go into subdirectory of the folders and take all the possible file URL. – Karmesh Duggar Jul 22 '22 at 10:47
  • 1
    "directory listing on" is very different from being able to extract data directly from the URL of a single file. It means a client can list directory contents without prior knowledge of the file names, which probably is what you're after. or are your files systematically named and numbered, so you could probe them? – Cee McSharpface Jul 22 '22 at 10:49
  • @CeeMcSharpface check the edited post please – Karmesh Duggar Jul 22 '22 at 11:25
  • 1
    To the best of my knowledge, `Directory.GetFiles` does not send requests to a web server when it gets a Url as an argument. It can only be used to query "disk-like" file systems. Is your code running on the webserver itself, so you could access the files directly, not via Url? – Cee McSharpface Jul 22 '22 at 11:28
  • @CeeMcSharpface yes they are systematically named,No code is not running on webserver.. Is there any other method to fetch the files Like Directory.GetFiles from a URL – Karmesh Duggar Jul 22 '22 at 15:06
  • yes, http GET. for a start: https://stackoverflow.com/a/308336/1132334 – Cee McSharpface Jul 22 '22 at 15:09
  • @CeeMcSharpface but this will only work for single URL it doesn't go in subdirectory and check all the files and return a list...what could we do any code could help please – Karmesh Duggar Jul 22 '22 at 15:25
  • without "directory listing" enabled, no way other than probing all the url paths one by one. should be possible to construct a list of url paths from the folder numbers. We don't write code for you here, but we can assist fixing an existing attempt. – Cee McSharpface Jul 22 '22 at 16:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246678/discussion-between-karmesh-duggar-and-cee-mcsharpface). – Karmesh Duggar Jul 22 '22 at 18:15

0 Answers0