zoukankan      html  css  js  c++  java
  • 读取文件夹中的文件

    public static void Main(string[] args)
            {
                DirectoryInfo dir = new DirectoryInfo(@"E:\书摘与插图\9");
                Addpicture.showDir(dir);
            }     

    namespace TaoBaoAddPicture
    {
        public class Addpicture
        {
            private static string FullName;
            private static int name;

            public static void showDir(DirectoryInfo dir)
            {
                Console.WriteLine(dir.Name);
                int i = 1;
                System.IO.FileInfo[] dirinfo = dir.GetFiles();     //获取文件夹下面的子文件
                foreach (FileInfo info in dirinfo)    //遍历子文件
                {
                   
                    bool status = true;
                    int s = info.Name.IndexOf('_');  
                    name = Convert.ToInt32(info.Name.Substring(0, s));   //截取“_“前的名字
                    FullName = info.Name;
                    string sql = string.Format("select outer_id from TaobaoPicture");
                    DataSet ds = DataDrive.sqlDataConn.connGetDataSetByExecSql(sql); //查询数据库
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                       
                        int sa = Convert.ToInt32(dr["outer_id"].ToString());
                        if (name == Convert.ToInt32(dr["outer_id"].ToString()))  //如果数据库中存在改文件子打印”已存在“并进入下一次遍历并将状态设为false
                        {
                            Console.WriteLine(string.Format("已存在第{0}个",i));
                            i++;
                            status = false;
                            break;
                        }
                    }

                   //如果数据库中不存在该条数据则执行run()
                     if (status)
                    {
                        run();
                        Console.WriteLine(name.ToString());
                        Console.WriteLine(info.Name);
                    }
                    //string sql = string.Format("insert into TaobaoPicture(outer_id) values({0})", name);
                    //DataDrive.sqlDataConn.connGetDataSetByExecSql(sql);

                }
            }

    上传图片
            public static void run()
            {
                string appkey = "12188005";
                string appsecret = "7e5a41417ae503f0499d071fc7c3cee4";
                string url = "http://gw.api.taobao.com/router/rest";
                ITopClient client = new DefaultTopClient(url, appkey, appsecret);
                PictureUploadRequest req = new PictureUploadRequest();
                req.ImageInputTitle = name.ToString();
                req.Img = new FileItem(@"E:\书摘与插图\9\" + FullName);
                req.PictureCategoryId = 303796891;
                req.Title = name.ToString(); ;
                PictureUploadResponse rsq = client.Execute(req);
                if (rsq.IsError)
                {
                    Console.WriteLine(rsq.ErrMsg);
                }
                else
                {
                    Console.WriteLine("图片上传成功【{0}】", FullName);
                }
            }
        }
    }

  • 相关阅读:
    组装树状结构文本框
    在jsp页面动态添加,删除文本框模块
    sql字段拆分 ,连表子查询获取值
    jsp页面技术总结
    C语言的基本数据类型
    如何学习一些需要算法的程序
    如何学习一门新的编程语言
    C++ 预处理器
    C++ 函数模板&类模板
    C++ 文件和流
  • 原文地址:https://www.cnblogs.com/happygx/p/1957976.html
Copyright © 2011-2022 走看看