コード例 #1
0
ファイル: Util.cs プロジェクト: mgdegroot/BulkDataMuncher
        /// <summary>
        ///
        ///
        /// </summary>
        /// <param name="srcFilename"></param>
        /// <param name="dstDirname"></param>
        /// <param name="overwrite"></param>
        private static Util.ReturnStuffer fileCopy(string srcFilename, string dstDirname, bool overwrite)
        {
            ReturnStuffer returnStuffer = new ReturnStuffer()
            {
                Result = false,
            };

            FileInfo file = new FileInfo(srcFilename);

            if (!file.Exists)
            {
                throw new FileNotFoundException("Source file not found: " + srcFilename);
            }

            if (!Directory.Exists(dstDirname))
            {
                throw new DirectoryNotFoundException("Destination directory not found: " + dstDirname);
            }
            string dstFilepath = Path.Combine(dstDirname, file.Name);

            try
            {
                file.CopyTo(dstFilepath, overwrite);
                returnStuffer.Files.Add(new FileSelection()
                {
                    Path = dstFilepath, State = FileState.TRANSFERRED, Type = FileSelectionType.FILE
                });
                Util.ProgressInfo.Increment();
                returnStuffer.Result = true;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("already exists"))
                {
                    returnStuffer.Files.Add(new FileSelection()
                    {
                        Path  = dstFilepath,
                        State = FileState.DUPLICATE,
                        Type  = FileSelectionType.FILE
                    });
                    returnStuffer.ErrMsg = ex.Message;
                    returnStuffer.Result = false;
                }
                else
                {
                    returnStuffer.Files.Add(new FileSelection()
                    {
                        Path  = dstFilepath,
                        State = FileState.ERROR,
                        Type  = FileSelectionType.FILE
                    });
                    returnStuffer.ErrMsg = ex.Message;
                    returnStuffer.Result = false;
                }
            }
            return(returnStuffer);
        }
コード例 #2
0
ファイル: Util.cs プロジェクト: mgdegroot/BulkDataMuncher
        private static ReturnStuffer directoryExists(string path)
        {
            ReturnStuffer result = new ReturnStuffer()
            {
                Result = Directory.Exists(path),
            };

            return(result);
        }
コード例 #3
0
ファイル: Util.cs プロジェクト: mgdegroot/BulkDataMuncher
        private static ReturnStuffer createDirectory(string path)
        {
            ReturnStuffer result = new ReturnStuffer()
            {
                Result = false,
            };

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            return(result);
        }
コード例 #4
0
ファイル: Util.cs プロジェクト: mgdegroot/BulkDataMuncher
        private static ReturnStuffer directoryCopy(string srcDir, string dstDir, bool recursive = true, bool overwrite = false)
        {
            ReturnStuffer result = new ReturnStuffer();

            // Directories keep their base -->
            dstDir = Path.Combine(dstDir, new DirectoryInfo(srcDir).Name);

            //Create all of the directories -->
            foreach (string dirPath in Directory.GetDirectories(srcDir, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(srcDir, dstDir));
                result.Files.Add(new FileSelection()
                {
                    Path  = dirPath.Replace(srcDir, dstDir),
                    State = FileState.TRANSFERRED,
                    Type  = FileSelectionType.DIRECTORY,
                });
            }


            // TODO: get total file count via other means if this is performance hit.... -->
            int fileCnt = Directory.GetFiles(srcDir, "*.*", SearchOption.AllDirectories).Length;

            Util.ProgressInfo.StepSize = 100 / fileCnt;

            //Copy all the files & Replaces any files with the same name -->
            foreach (string newPath in Directory.GetFiles(srcDir, "*.*", SearchOption.AllDirectories))
            {
                File.Copy(newPath, newPath.Replace(srcDir, dstDir), overwrite);
                result.Files.Add(new FileSelection()
                {
                    Path = newPath.Replace(srcDir, dstDir), State = FileState.TRANSFERRED, Type = FileSelectionType.FILE
                });

                Util.ProgressInfo.Increment();
            }

            return(result);
        }