예제 #1
0
        private static List <FileSystemInfo> GetFiles(DirectoryInfo dirInfo, List <FileSystemInfo> fileList)
        {
            var fsInfos = dirInfo.GetFileSystemInfos();

            foreach (var fsInfo in fsInfos)
            {
                if (fsInfo is DirectoryInfo)
                {
                    GetFiles(new DirectoryInfo(fsInfo.FullName), fileList);
                }
                else
                {
                    var fileExt = fsInfo.Extension.ToLower();
                    if (PicExt.Contains(fileExt) || VidExt.Contains(fileExt))
                    {
                        fileList.Add(fsInfo);
                    }
                }
            }
            return(fileList);
        }
예제 #2
0
        internal static bool FileProcess(FileSystemInfo file)
        {
            try {
                string strDt;
                var    fileExt = file.Extension.ToLower();
                if (PicExt.Contains(fileExt))
                {
                    var dictResult = MetaQuery(file, true);
                    if (dictResult == null)
                    {
                        Console.WriteLine("[-Error-] Pic MetaQuery returns NULL result: " + file.FullName + ".");
                        return(false);
                    }
                    else if (dictResult.ContainsKey("error"))
                    {
                        Console.WriteLine("[-Error-] Pic MetaQuery error: " + dictResult["error"] + ".");
                        return(false);
                    }
                    else
                    {
                        strDt = dictResult["datetime"];
                        Rename(file, strDt);
                    }
                }
                else if (VidExt.Contains(fileExt))
                {
                    var dictResult = MetaQuery(file, false);
                    if (dictResult == null)
                    {
                        Console.WriteLine("[-Error-] Vid MetaQuery returns NULL result: " + file.FullName + ".");
                        return(false);
                    }
                    else if (dictResult.ContainsKey("error"))
                    {
                        Console.WriteLine("[-Error-] Pic MetaQuery error: " + dictResult["error"] + ".");
                        return(false);
                    }
                    else
                    {
                        strDt = dictResult["datetime"];
                        Rename(file, strDt);
                    }
                }
                else
                {
                    var dictResult = MetaQuery(file, true);
                    // try as pic
                    if (dictResult == null || dictResult.ContainsKey("error"))
                    {
                        dictResult = MetaQuery(file, false);
                        // or else try as vid
                    }

                    if (dictResult == null)
                    {
                        Console.WriteLine("[-Error-] MetaQuery returns NULL result: " + file.FullName + ".");
                        return(false);
                    }
                    else if (dictResult.ContainsKey("error"))
                    {
                        Console.WriteLine("[-Error-] MetaQuery error: " + dictResult["error"] + ".");
                        return(false);
                    }
                    else
                    {
                        strDt = dictResult["datetime"];
                        Rename(file, strDt);
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("[-Error-] FileProcess error: " + ex.Message + ".");
                return(false);
            }

            return(true);
        }