Hi,
I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..???
Thanks in advance..
Hi,
I am into automation work. Is there any UNIX command to rename a file in a zipped folder, without unzipping it..???
Thanks in advance..
Seems to be possible with libzip, though that's just a function, not an executable. seeing what I can find that uses it...
---------- Post updated at 04:09 PM ---------- Previous update was at 03:55 PM ----------
Here's a quick program using libzip:
#include <stdio.h>
#include <zip.h>
#include <errno.h>
int main(int argc, char *argv[])
{
int n, err, index=-1;
struct zip *z;
if(argc != 4)
{
printf("syntax: %s file.zip oldname newname\n", argv[0]);
return(1);
}
z=zip_open(argv[1], 0, &err);
if(z == NULL)
{
char buf[512];
zip_error_to_str(buf, 512, err, errno);
fprintf(stderr, "Couldn't open zip: %s\n", buf);
}
for(n=0; n<zip_get_num_files(z); n++)
{
const char *name=zip_get_name(z, n, 0);
if(strcmp(name, argv[2]) == 0)
{
index=n;
break;
}
}
if(index < 0)
{
fprintf(stderr, "Couldn't find %s\n", argv[2]);
return(1);
}
fprintf(stderr, "Found %s at %d\n", argv[2], index);
if(zip_rename(z, index, argv[3]) < 0)
{
fprintf(stderr, "Couldn't rename file\n");
zip_close(z);
return(1);
}
zip_close(z);
return(0);
}
Compile with -lzip.