0

The script is working perfectly fine. The only issue I am facing is path. Once the zip file is created. If I unzip its. its having a complete path of the file like:--

/name_the_file/Users/user_name/projects/project_name/public/system/files/10/original/*

I just want to make it

name_of_the_file/*

 desc "Create Zip file"
  task :create_zip => :environment do
  directory_path = "#{RAILS_ROOT}/public/system/files/10/original"
  bundle_filename="#{directory_path}/"+ "name_of_file.zip"
  filenames = "#{directory_path}/*" 
  %x{ cd #{directory_path}}
  %x{  zip -r  #{bundle_filename}  #{filenames}}
end

PS:- I want to create zip files. No tar, gzip etc

2 Answers 2

2

Here is the solution:--

  %x{  zip -r -j  #{bundle_filename}  #{filenames}}

Normally this would result in a zip containing three "subdirs":

a/
+ file1

b/
+ file2

c/
+ file3

With -j, you get:

./
+ file1
+ file2
+ file3
Sign up to request clarification or add additional context in comments.

Comments

1

You are supplying the entire directory path with each filename. Since you have already changed to that directory, you don't need to do that.

In other words, if you change your filenames variable to:

filenames = "*"

It should work as you intend.

3 Comments

. Its not working. I am not able to change my directory from projectname Check edit part
It may be spawning two distinct subshells. Try %x{ cd #{directory_path}; pwd }
%x{ zip -r -j #{bundle_filename} #{filenames}} worked. -j is the option not to save the path..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.