将某目录文件打成tar包
2016-04-21 16:35
176 查看
要点:
1、char tarName[100] = {0};
sprintf(tarName , "tar -cvf data.tar %s" , tarPath);// 把某个路径(tarPath)做成一个名为 data.tar 的归档包
//其中sprintf()的作用是将后面的路径做成一个字符串
2、system(tarName);
//system(const char*) 是系统调用执行该命令(命令已写成字符串形式)
源代码:
#include<stdlib.h>
#include<stdio.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
//这是初始包目录 做成一个初始包
char *tarPath = "/home/client/walk_dir/test/";
#define TAR_LARGE_SIZE 4*1024*1024
void send_small_file(char *path)
{
char tarName[100] = {0};
// 把某个路径(tarPath)做成一个名为 data.tar 的归档包
sprintf(tarName , "tar -cvf data.tar %s" , tarPath);
system(tarName);
struct stat stateTar;
if (stat(path, &stateTar) != 0) {
puts("file does not exist! ignored!\n");
return;
}
struct stat state;
if (stat(path, &state) != 0) {
puts("file does not exist! ignored!\n");
return;
}
//往包tar里面追加新的文件 ,小于4兆则添加(打包成小于4兆的文件)
if(stateTar.st_size + state.st_size <= TAR_LARGE_SIZE)
{
char tempCmd[100] = {0};
sprintf(tempCmd , "tar -rv -f data.tar %s" , path);
system(tempCmd);
printf("tar tianjia cheng gong!\n");
return ;
}
else
{
printf("tar yi man!\n");//tar的路径可以使用了
return ;
}
}
int main(int arg , char** arv)
{
char *path = "/home/client/walk_dir/temp/";
send_small_file(path);
return 0;
}
1、char tarName[100] = {0};
sprintf(tarName , "tar -cvf data.tar %s" , tarPath);// 把某个路径(tarPath)做成一个名为 data.tar 的归档包
//其中sprintf()的作用是将后面的路径做成一个字符串
2、system(tarName);
//system(const char*) 是系统调用执行该命令(命令已写成字符串形式)
源代码:
#include<stdlib.h>
#include<stdio.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
//这是初始包目录 做成一个初始包
char *tarPath = "/home/client/walk_dir/test/";
#define TAR_LARGE_SIZE 4*1024*1024
void send_small_file(char *path)
{
char tarName[100] = {0};
// 把某个路径(tarPath)做成一个名为 data.tar 的归档包
sprintf(tarName , "tar -cvf data.tar %s" , tarPath);
system(tarName);
struct stat stateTar;
if (stat(path, &stateTar) != 0) {
puts("file does not exist! ignored!\n");
return;
}
struct stat state;
if (stat(path, &state) != 0) {
puts("file does not exist! ignored!\n");
return;
}
//往包tar里面追加新的文件 ,小于4兆则添加(打包成小于4兆的文件)
if(stateTar.st_size + state.st_size <= TAR_LARGE_SIZE)
{
char tempCmd[100] = {0};
sprintf(tempCmd , "tar -rv -f data.tar %s" , path);
system(tempCmd);
printf("tar tianjia cheng gong!\n");
return ;
}
else
{
printf("tar yi man!\n");//tar的路径可以使用了
return ;
}
}
int main(int arg , char** arv)
{
char *path = "/home/client/walk_dir/temp/";
send_small_file(path);
return 0;
}
相关文章推荐
- 伪静态URLRewrite学习笔记
- iOS远程推送代码分析
- postgres数据库创建主分表的语法
- 干货:结合Scikit-learn介绍几种常用的特征选择方法
- 近5年133个Java面试问题列表
- Just write the code
- VB--乘法
- Qt中使用Firebird 和 Firebird Embedded
- winform学习目录
- Json字符串转成XML
- hdu3746(next数组解决)
- qt 设置窗口圆角
- Linux 常用命令
- iOS Apple Pay详解以及处理支付逻辑(附带Demo)
- java要注意的问题2
- Monkey测试log的保存与分析
- 数轴上从左到右有n个点a[0],a[1]…,a[n-1],给定一根长度为L的绳子,求绳子最多能覆盖其中的几个点。要求算法复杂度为o(n)。
- 冒泡排序
- 当网页加载很慢的时候,应如何分析其原因并解决问题?
- opencv实现 Matlab 寻找峰值函数 findpeaks