该脚本剔除某目录下不规范的子目录名

类别:软件工程 点击:0 评论:0 推荐:

用c的脚本pike写的,当然用别的也可以实现

int main()
{
        string cmd2="cd /home/xxx/u;ls -l |grep ^d > /home/xxx/findsavedir.txt";
        Process.system(cmd2);
        write("列出存档文件夹完毕!\n");
        string strlist = Stdio.read_file("/home/xxx/findsavedir.txt");
        array(string) split_str=strlist/"\n";

        foreach(split_str,string str)
        {
                if(str=="null"||str=="\r"||str=="\n"||str=="\r\n")
                        continue;

                string s;

                if( sizeof(str)==59 )//该目录长度,根据情况自定,我要查找的子目录都是2位的,所以这样写
                {
                        s=str[57..sizeof(str)];
                        if(s[0]>='0'&&s[0]<='9'&&s[1]>='0'&&s[1]<='9')//非字符或者数字做文件目录的都剔除
                        {
                                string usertmp = "cd /home/xxx/u; cp -fr "+ s +" ../u.right.bak/";
                                string usertmp_in = "cd /home/xxx/u; cp -fr "+ s +" ../u.right.bak/\n";
                                Process.system(usertmp);
                                Stdio.append_file("copydir.txt",usertmp_in);//最好在Process.system先看看copydir.txt文件有没有问题再执行.
                        }
                        else
                        {
                        }
                }
        }
}

 

本文地址:http://com.8s8s.com/it/it32850.htm