How do I rename a dowloaded file using cURL
I have a list of file locations on a website that I need to download to a specific folder on my desktop.
I want to rename each file as it downloads is this possible with cURL?
do shell script “cd ~/Desktop/Images; curl -fO '[url=http://www.oooooo.com/library/image1.jpg]http://www.oooooo.com/library/image1.jpg’[/url]'”
What about specifying the -o (output file) parameter?
set destFolder to (path to desktop as text) -- folder
set filename to text returned of (display dialog "give a name for the image" default answer "Downloaded") -- name for dest file
set destFile to destFolder & filename -- full path
DownloadSource_toFile("http://www.vreden.de/publish/binarydata/hallenplan/handball_icon.jpg", destFile)
on DownloadSource_toFile(fileURL, destHSF)
-- construct destHSF
set fileExt to pathExtension(fileURL)
if pathExtension(destHSF) is not fileExt then set destHSF to destHSF & "." & fileExt
do shell script "curl " & quoted form of fileURL & " -o " & quoted form of (POSIX path of destHSF)
end DownloadSource_toFile
(* =========== PATH FUNCTIONS =============== *)
on pathComponents(filename)
if filename is "" then return {}
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set components to every text item of filename
set AppleScript's text item delimiters to ""
if filename starts with "/" then set item 1 of components to "/"
-- if end with slash
if item -1 of components is "" then set components to (items 1 thru -2 of components)
set AppleScript's text item delimiters to tid
return components
end pathComponents
on lastPathComponent(filename)
set allComponents to my pathComponents(filename)
if allComponents is {} then return ""
return item -1 of allComponents
end lastPathComponent
on pathExtension(filename)
set fName to lastPathComponent(filename)
if fName does not contain "." then -- no dot
set ext to ""
else if fName is "." then -- only dot
set ext to ""
else if fName starts with "." and (characters 2 thru -1 of fName) as text does not contain "." then -- starts dot, but no second dot
set ext to ""
else
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set textItems to every text item of fName
set AppleScript's text item delimiters to tid
set ext to item -1 of textItems
end if
return ext
end pathExtension
Hope it helps,
ief2