Downloading files from an internet directory

9 views (last 30 days)
Joe
Joe on 11 Nov 2011
Commented: dsmalenb on 1 Jun 2019
So I have a function that will grab files from a directory on my computer and iterate through each one and perform the task I want to each file.
I have to do this to a couple thousand files on one website and then later on I'll have to do it with several others so I want to try to automate the process so that I don't have to save each file into a directory on my computer first.
Here is what I thought could work, but it it doesn't. When I run it the dir() commmand returns a 0x1 struct. Therefore the second part of the program doesn't work. If I type the URL with file name directly into the urlwrite() command it works, but that only gets me one file at a time and I might as well save them like I have been.
So here is the code and let me know what you think or if there is a better way of doing this.
file = dir('http://blizzard.mtukrc.org/~weather/KRCwthr*.csv')
for i = 1:numel(file)
urlwrite ('http://blizzard.mtukrc.org/~weather/',file(i).name)
end
The URL I am trying to get the files from is http://blizzard.mtukrc.org/~weather if it wasn't already obvious. I want to download all of the .csv files that begin with "KRCwrth*.csv." Thanks in advance for the help!

Answers (1)

Jan
Jan on 11 Nov 2011
dir works with URLs, if you open a connection using the ftp command, see ftp.dir
I'd prefer mget.
  3 Comments
J Travis Hunsucker
J Travis Hunsucker on 15 Oct 2018
Jan- I cannot get dir to work with a url in R2018. Do you have any suggestions on how to query a folder using a url? Thank you
dsmalenb
dsmalenb on 1 Jun 2019
Did you ever figure this out without the ftp server info? I have the same issue

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!