Created
July 19, 2013 14:19
-
-
Save chaserx/6039440 to your computer and use it in GitHub Desktop.
various failed attempts to remove non-empty folder via FTP cobbled together from example code and internal methods from various stackoverflow answers and gems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGEX = /^(?<type>.{1})(?<mode>\S+)\s+(?<number>\d+)\s+(?<owner>\S+)\s+(?<group>\S+)\s+(?<size>\d+)\s+(?<mod_time>.{12})\s+(?<filename>.+)$/ | |
def delete_directory_contents(path, verbose = true) | |
# files = @ftp_conn.nlst(path) | |
# files.each do |file| | |
# if directory?("#{path}/#{file}") | |
# delete_directory_contents "#{path}/#{file}" | |
# @ftp_conn.rmdir("#{path}/#{file}") | |
# else | |
# @ftp_conn.delete("#{path}/#{file}") | |
# end | |
# end | |
# @ftp_conn.rmdir(path) | |
########### | |
# recurse = [] | |
# @ftp_conn.list(path) do |e| | |
# entry = Net::FTP::List.parse(e) | |
# match_data = e.match(REGEX) | |
# @paths = "#{path}/#{entry.basename}".gsub(/\/+/, '/') | |
# if entry.dir? | |
# recurse << @paths | |
# elsif entry.file? | |
# @ftp_conn.delete("#{path}/#{match_data[:filename]}") | |
# else | |
# # | |
# end | |
# recurse.each do |r| | |
# delete_directory_contents(r) | |
# end | |
# end | |
########### | |
# begin | |
# puts "begin" | |
# flist = @ftp_conn.nlst(path) | |
# flist.each do |f| | |
# # Try to delete the file. If we fail then it's a directory | |
# begin | |
# puts "internal begin" | |
# if directory?(File.join(path,f)) | |
# rmrf_dir(File.join(path,f)) | |
# else | |
# @ftp_conn.delete(File.join(path,f)) | |
# puts "rm #{f}" if verbose | |
# end | |
# rescue Exception => e | |
# rmrf_dir(File.join(path,f), verbose) | |
# end | |
# end | |
# rescue Exception => e | |
# # If the directory is empty, error silently and continue execution | |
# end | |
# @ftp_conn.rmdir(path) | |
# puts "rm -rf #{path}" if verbose | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment