Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 8th, 2005, 6:50 PM   #1
Master
Programmer
 
Master's Avatar
 
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3 Master is on a distinguished road
Smile Recycler Bin emulator

This code basically let you remove a folder that contain files, meaning you can create folders to store file that are useless then simply run my program and typing the directory will empty. I know some people would be wondering why i made this when there is a recycler bin already. i just did this so i can easily delete files from my computer without looking for the folders and such.


here is the code. I wrote it in ruby.

  def delete_file(name)
  dir = name
  begin
   file = Dir.entries(dir)
   rescue SystemCallError
 end
   file.delete(".") if file.is_a?(Array)
   file.delete("..") if file.is_a?(Array)
if file.is_a?(Array)
puts "Files In Folder"
for i in 0...file.size
puts file[i].to_s + "\n"
sleep(0.2)
end
puts "\n\n"
puts "File Deleting in progress\n\n"
sleep(0.2)
  for i in 0...file.size
  unless FileTest.directory?(dir + "/#{file[i]}")
    File.delete(dir + "/#{file[i]}") if FileTest.exists?(dir + "/#{file[i]}")
    puts file[i].to_s + " deleted\n"
    sleep(0.2)
    puts ((file.size - 1) - i).to_s + " remaining\n"
    sleep(0.2)
    else
    file_d = Dir.entries(dir + "/#{file[i]}")
    file_d.delete(".")  if file_d.is_a?(Array) 
    file_d.delete("..") if file_d.is_a?(Array)
    if file_d.is_a?(Array)
    dirr = dir + "/#{file[i]}"
    puts "Folder Found\n"
    puts "Folder Name = '#{file[i]}'\n"
    puts "Emptying Folder....\n"
    for i in 0...file_d.size
	File.delete(dirr + "/#{file_d[i]}") if FileTest.exists?(dirr + "/#{file_d[i]}")
	puts file_d[i].to_s + " deleted\n"
	sleep(0.2)
	puts ((file_d.size - 1) - i).to_s + " remaining\n"
	sleep(0.2)
    end
    end
    Dir.delete(dirr)
    end
   end
  begin
    Dir.delete(dir)
    rescue SystemCallError
  end
  start()
  else
  puts "\n#{name} does not exist\n"
  start()
 end
 while input = STDIN.gets
	 input.chop!
	  if input == "exit"
	  puts "Program is existing...."
	  exit()
	  end
 end
 end
 
 def start()
 puts "Please Specify the Directory Name to Empty\n"
 while get = STDIN.gets
	 get.chop!
	 delete_file(get)
end
end

start()
Master is offline   Reply With Quote
Old Nov 8th, 2005, 6:53 PM   #2
Master
Programmer
 
Master's Avatar
 
Join Date: Sep 2005
Location: GA
Posts: 99
Rep Power: 3 Master is on a distinguished road
Sorry, can a moderator move this please. I posted it on the wrong place.
Master is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC