Class: Fos::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/fos.rb

Instance Method Summary collapse

Instance Method Details

#moveObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fos.rb', line 5

def move
  
  # General Variables
  username = File.expand_path('~')
  folder = "archive" # New Folder Name
  today = Time.now.strftime("%B %e %Y").gsub(' ', '_').gsub(/:.*/, '')
  default_folders = ['Desktop', 'Downloads']
  
  # Do for each folder
  default_folders.each do |this_folder|
    
    # Get Path
    current_path = "#{username}/#{this_folder}"
    
    # Get Files
    current_files = Dir.entries(current_path)
    
    # Create Folders
    if !File.directory?("#{current_path}/#{folder}")
      `mkdir #{current_path}/#{folder}`
    end
    if !File.directory?("#{current_path}/#{folder}/#{today}")
      `mkdir #{current_path}/#{folder}/#{today}`
    end
    
    # Remove System Folders And Our New Folder
    current_files.delete_if{|x| (x =~ /^\./) == 0 }
    current_files.delete_if{|x| x == "#{folder}"}
    current_files.delete_if{|x| (x =~ /Macintosh/) == 0}
      
    # Clean File names
    current_files = current_files.map{|x| x.gsub(" ", '\ ').gsub("(", '\(').gsub(")", '\)')}
    
    # Do The Moving
    current_files.each do |filename|
      `mv #{current_path}/#{filename} #{current_path}/#{folder}/#{today}`
    end
    
    # Finished
    puts "Cleaned #{current_path}"
    
  end
  
end