1. Direct implementation via C
#include <stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<unistd.h>intfilenum=0;Charfilenam[Ten];CharFileName () {filenam[Ten]=0; FileNum+=1; Charstr[4]; Chars1[]="./image/"; Chars2[]=". YUV"; sprintf (str,"%d", FileNum); sprintf (Filenam,"%s%s%s", S1,STR,S2); }intMainintargcChar*argv[]) { intFD_SRC,FD_DST; Charbuf[245120]; intN; if((Fd_src=open ("./raw.data", o_rdonly)) <0) {perror ("Open src"); Exit (Exit_failure); } while(N=read (Fd_src,buf,sizeof(BUF))) >0){ if(n! =245120) {perror ("File Size Small"); Close (FD_SRC); Exit (Exit_failure); } //Lseek (fd_src,245120,seek_cur);FileName (); if(FD_DST = open (filenam,o_creat| O_wronly,0666) <0) {perror ("Open DST fail"); Close (FD_SRC); Exit (Exit_failure); } write (Fd_dst,buf,n); printf ("copy successfully\n"); Close (FD_DST); System ("./move.sh"); } printf ("copy successfully\n"); Close (FD_SRC); Exit (exit_success); }
View Code
2. Execute the script by calling the system function
#! /bin/SHfile_name () {RM./image/1. txtTouch./image/1. txtchmod 777./image/1. txtls-L Image |Cut-D' '-FTen|Cut-D'.'-F1>./image/1. txt num=$(Tail./image/1. txt-n1) Echo "$num"Num=$ (($num +1)) Echo "$num"}move () {file_nameMV./image/0. YUV./image/"$num". YUV}move
View Code
Linux breaks down a file into multiple different file names