示例#1
0
        static void Main(string[] args)
        {
            string selectPath = @"\\10.3.2.19\指数数据备份\天相指数\";

            SharedFile.CheckSharedFile("", "", selectPath);
            var dicInfo = new DirectoryInfo(selectPath);//选择的目录信息

            DirectoryInfo[] dic = dicInfo.GetDirectories("*.*", SearchOption.TopDirectoryOnly);
            foreach (DirectoryInfo temp in dic)
            {
                Console.WriteLine(temp.FullName);
            }

            Console.WriteLine("---------------------------");
            FileInfo[] textFiles = dicInfo.GetFiles("*.*", SearchOption.TopDirectoryOnly);//获取所有目录包含子目录下的文件
            foreach (FileInfo temp in textFiles)
            {
                Console.WriteLine(temp.Name);
            }
            Console.ReadKey();
        }
示例#2
0
        public static void CheckSharedFile(string userName, string password, string selectPath)
        {
            string error = "";

            try
            {
                SharedFile      _dir = new SharedFile(userName, password, selectPath);
                var             dirs = new DirectoryInfo(selectPath);//选择的目录信息
                DirectoryInfo[] ds   = dirs.GetDirectories("*.*", SearchOption.TopDirectoryOnly);
                //error = (Utils.IsEmpty(_dir.Error)) ? "" : _dir.Error;
                if (ds.Length == 0)
                {
                    error = selectPath + ",共享目录无法访问.";
                }
                //Utils.WriteTxtFile(selectPath + @"pdf\A股\a.txt", "检测共享目录:" + selectPath, true);
            }
            catch (Exception ex)
            {
                error = "检测共享目录异常:" + ex.Message + ex.StackTrace + "\n" + selectPath + "\n" + userName + "\n" + password;
            }
        }