Hello, Can anyone help me or give me any clue on how to rename a file (or folder) inside a zip file without having to unzip it first. I''m trying to do this using the rubyzip gem without luck. Thanks, Elías
You must require ''zip/zipfilesystem'' and Zip::ZipFile.open(''my.zip'') do |zipfile| zipfile.file.rename ''orignal_name.txt'', ''new_name.txt'' end And this is it, for more information see the Zip::ZipFileSystem class documentation. Regards. Franco Catena. On Apr 27, 12:12 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > Can anyone help me or give me any clue on how to rename a file (or > folder) inside a zip file without having to unzip it first. I''m trying > to do this using the rubyzip gem without luck. > > Thanks, > > Elías
Hi Franco, Thanks for your reply, but still it ain''t working for. I need to rename a folder not a file. It works fine for file but not for folders. I tried this and it correctly renamed the file build.yml to builder.yml, BUT the folder wasn''t rename, instead it created a new folder in the same level of the one I wanted to rename. Any clues? Zip::ZipFile.open(''/home/elioncho/Desktop/MyApp.zip''){|zf| parent_folder = zf.get_entry(''Test/'') file = zf.get_entry(''Prueba/build.yml'') parent_folder.name = ''Prueba/testing/'' file.name = ''Prueba/builder.yml'' } On Apr 27, 11:39 am, Franco Catena <francocat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You must require ''zip/zipfilesystem'' and > > Zip::ZipFile.open(''my.zip'') do |zipfile| > zipfile.file.rename ''orignal_name.txt'', ''new_name.txt'' > end > > And this is it, for more information see the Zip::ZipFileSystem class > documentation. > > Regards. > > Franco Catena. > > On Apr 27, 12:12 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello, > > > Can anyone help me or give me any clue on how to rename a file (or > > folder) inside a zip file without having to unzip it first. I''m trying > > to do this using the rubyzip gem without luck. > > > Thanks, > > > Elías
I copied a wrong code, here it is. As I say before it only works for renaming the file not the folder. Zip::ZipFile.open(''/home/elioncho/Desktop/MyApp.zip''){|zf| parent_folder = zf.get_entry(''Test/'') file = zf.get_entry(''Test/build.yml'') parent_folder.name = ''Testing/'' file.name = ''Test/builder.yml'' } On Apr 27, 11:58 am, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Franco, > > Thanks for your reply, but still it ain''t working for. I need to > rename a folder not a file. It works fine for file but not for > folders. I tried this and it correctly renamed the file build.yml to > builder.yml, BUT the folder wasn''t rename, instead it created a new > folder in the same level of the one I wanted to rename. Any clues? > > Zip::ZipFile.open(''/home/elioncho/Desktop/MyApp.zip''){|zf| > parent_folder = zf.get_entry(''Test/'') > file = zf.get_entry(''Prueba/build.yml'') > parent_folder.name = ''Prueba/testing/'' > file.name = ''Prueba/builder.yml'' > } > > On Apr 27, 11:39 am, Franco Catena <francocat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You must require ''zip/zipfilesystem'' and > > > Zip::ZipFile.open(''my.zip'') do |zipfile| > > zipfile.file.rename ''orignal_name.txt'', ''new_name.txt'' > > end > > > And this is it, for more information see the Zip::ZipFileSystem class > > documentation. > > > Regards. > > > Franco Catena. > > > On Apr 27, 12:12 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello, > > > > Can anyone help me or give me any clue on how to rename a file (or > > > folder) inside a zip file without having to unzip it first. I''m trying > > > to do this using the rubyzip gem without luck. > > > > Thanks, > > > > Elías
There is no method to directly rename a directory, you must use the rename in every file between the directory like this: Zip::ZipFile.open(''my.zip'') do |zipfile| zipfile.file.rename ''original_dir/orignal_name.txt'', ''new_dir/ original_name.txt'' end And after that you can remove the original directory. Regards. Franco Catena. On Apr 27, 2:00 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I copied a wrong code, here it is. As I say before it only works for > renaming the file not the folder. > > Zip::ZipFile.open(''/home/elioncho/Desktop/MyApp.zip''){|zf| > parent_folder = zf.get_entry(''Test/'') > file = zf.get_entry(''Test/build.yml'') > parent_folder.name = ''Testing/'' > file.name = ''Test/builder.yml'' > } > > On Apr 27, 11:58 am, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Franco, > > > Thanks for your reply, but still it ain''t working for. I need to > > rename a folder not a file. It works fine for file but not for > > folders. I tried this and it correctly renamed the file build.yml to > > builder.yml, BUT the folder wasn''t rename, instead it created a new > > folder in the same level of the one I wanted to rename. Any clues? > > > Zip::ZipFile.open(''/home/elioncho/Desktop/MyApp.zip''){|zf| > > parent_folder = zf.get_entry(''Test/'') > > file = zf.get_entry(''Prueba/build.yml'') > > parent_folder.name = ''Prueba/testing/'' > > file.name = ''Prueba/builder.yml'' > > } > > > On Apr 27, 11:39 am, Franco Catena <francocat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > You must require ''zip/zipfilesystem'' and > > > > Zip::ZipFile.open(''my.zip'') do |zipfile| > > > zipfile.file.rename ''orignal_name.txt'', ''new_name.txt'' > > > end > > > > And this is it, for more information see the Zip::ZipFileSystem class > > > documentation. > > > > Regards. > > > > Franco Catena. > > > > On Apr 27, 12:12 pm, elioncho <elion...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, > > > > > Can anyone help me or give me any clue on how to rename a file (or > > > > folder) inside a zip file without having to unzip it first. I''m trying > > > > to do this using the rubyzip gem without luck. > > > > > Thanks, > > > > > Elías