Windows directory structure


#1

Hi All,
I am using directory resource with recursive option in windows.
I want to create below folders.
“Program files”
“SFTP Users"
Directories but its creating below structure
"Programe”
“files”
"SFTP "
“Users”

can you please help here with creation of directories with space.

Recipe code:-
%w[ Program Files
SFTP users\Alloc_SFTP ].each do |path|
directory path do
recursive true
action :create
end
end


#2

Because you are doing %w[ Program Files SFTP users\Alloc_SFTP].each ruby is interpreting each word in that array to be an individual path.

By simply removing the word array it should do what you want. Make sure to escape any back slashes

directory 'c:\\Program Files\\SFTP\\users\\Alloc_SFTP' do
  recursive true
  action :create
end

or

directory 'c:/Program Files/SFTP/users/Alloc_SFTP' do
  recursive true
  action :create
end

#3

U can use arrays to define folders which needed to be create.

Double slash in path for windows platform

folders = ['C:\\Program files\\', 'C:\\Program files\\MyAwesomeDir', 'C:\\Program files\\MyAwesomeDir2']

folders.each do |folder|
  directory folder do
     recursive true
     action :create
  end
end