I am new to programming and I have just written my first program. It takes files from an SD card and copies then into a new named folder and has the option to name the files themselves or simply move them into the named folder.
As I am new I am unsure of the correct convention in terms of layout or structure of a program. Would a 'real' program look like this and how should it be structured?
Dir.chdir '/home/moot/pickaxe/pics' #replace this with destination directory
$pic_names = Dir['/media/moot/**/*.{CR2,cr2,JPG,jpg}'] #replace this with sd card directory
def folder
puts "Enter the folder name"
while $folder_name = gets.chomp
if File.exist?("#{$folder_name}")
puts "This folder already exists, choose a unique name"
else
require 'fileutils'
FileUtils::mkdir_p "/home/moot/pickaxe/pics/#{$folder_name}"
break
end
end
end
def files
puts "Do you want to name the files? Answer y/n"
while question = gets.chomp
if question == "y"
puts "What do you want to call them?"
$file_name = gets.chomp
print "Downloading #{$pic_names.length} Files: "
pic_number = 1
$pic_names.each do |name|
print 'ˁ˚ᴥ˚ˀ '
new_name = if pic_number < 10
"#{$file_name} 0#{pic_number} .CR2"
else
"#{$file_name} #{pic_number} .CR2"
end
require 'fileutils'
include FileUtils
cp(name, new_name)
pic_number = pic_number + 1
end
break
elsif question == "n"
print "Downloading #{$pic_names.length} Files: "
$pic_names.each do |name|
print 'ˁ˚ᴥ˚ˀ '
new_dir = "/home/moot/pickaxe/pics/#{$folder_name}"
require 'fileutils'
include FileUtils
cp(name, new_dir)
end
break
else
puts "Please answer y/n"
end
end
end
folder
Dir.chdir "/home/moot/pickaxe/pics/#{$folder_name}"
files
puts "Move Complete."