Jump to content

Ruby creating directories in a loop


Recommended Posts

Hi

I am frustrated from this simple task, I've been testing this script for two hours trying to find the problem but no luck!

 

 

My script reads a command line argument(ARGV[0]), then creates a directory named as #{ARGV[0]},

then it reads the DATA object (after the __END__ which looks below), and create those directories inside ARGV[0]

 

__END__
app/views/layouts
app/models
app/controllers
config
db
doc
lib
public/javascripts
public/stylesheets
public/images
log

 

 

note that I am using Notpad++ and i have EOL set to UNIX, so it is NOT supposed to cause any \n troubles

My script  creates what looks like directories, i can see them in my FTP but I can't delete any!

when I asked my instructor about it, he said, review your code, lib (directory) is NOT like lib?

 

so I am wondering where did the question mark come from?

also note that I do NOT see ?  when i use SSH client or FTP!

i had to run another script to delete these weird directories

 

this is my script


require 'fileutils'
include FileUtils

	if ARGV.empty?
	  puts "__________________________________________ _ _"
	  puts " "
	  puts "USAGE: ruby script/generate.rb Your_Site_Name"
	  puts "__________________________________________ _ _"


	elsif Dir.exists?("/home/students/myname/public_html/cis113/#{ARGV[0]}")
		puts "This directory already exist!"
		puts "Would you like to use the existing directory (Y/N)?"
			#I need help with this part later

	 #read DATA and create directories
	else
		Dir.mkdir("/home/students/myname/public_html/cis113/#{ARGV[0]}")
		DATA.each do |line|
			FileUtils.mkpath ("/home/students/myname/public_html/cis113/#{ARGV[0]}/#{line}")
		end
		
	end	

help is highly appreciated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.