none
Problem to copy file RRS feed

  • Question

  • Hi,

    How to adjust copy line below

            static void DirSearch(string directoryPath,string par_OutFile)
            {
                string line;
                string OutFile = par_OutFile;
                string Name1 = "", Name_H = "";
                string AccessTime1 = "";
                string WriteTime1 = "";
                int Pos0, Pos1, Pos2, Pos3;
    
                ...
                bool Cont0 = true;
                string f0 = "", s0 = "", d0 = "";
                int pos0 = 0, pos1 = 0, pos2 = 0;
                try
                {
                    string [] fileEntries = Directory.GetFiles(directoryPath);
                    foreach (string fileName in fileEntries)
                    {
                        Cont0 = true;
                        using (StreamReader sr = new StreamReader(@fileName, Encoding.Default))
                        {
                            while ((line = sr.ReadLine()) != null && Cont0)
                            {
                                for (int j = 0; j < list1.Count; ++j)
                                {
                                    if (Cont0)
                                    {
                                        if (line.IndexOf(list1[j].Trim()) >= 0)
                                        {
                                            using (StreamWriter sw = new StreamWriter(@OutFile, true, Encoding.Unicode))
                                            {
                                                //sw.WriteLine("Total number of files within folder - " + FullPath0 + " --> " + TotalFile.ToString().Trim());
                                                //sw.WriteLine(fileName + " " + line);
                                                sw.WriteLine(fileName);
                                                //sw.WriteLine((Att0.ToString().Trim() == "Directory" ? "Directory - " : "File - ") + Name.ToString().Trim() + " Access time - " + AccessTime.ToString().Trim() + " Write time - " + WriteTime.ToString().Trim());
                                            }
                                            pos0 = fileName.IndexOf("_");
                                            pos1 = fileName.Length;
                                            f0 = "CSI" + fileName.Substring(0, pos0 + 1) + "SA1_" + fileName.Substring(pos0 + 1, pos1 - 1 - pos0);
                                            s0 = System.IO.Path.Combine(@"e:\3b", fileName); d0 = System.IO.Path.Combine(@"e:\out0", f0);
                                            System.IO.File.Copy(@fileName, d0, true);
                                            Cont0 = false;
                                        }
    

    due to following exception

    Exception/StackTrace - The given path's format is not supported.    at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
       at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
       at ScanFolder.Program.DirSearch(String directoryPath, String par_OutFile) in c:\ScanEDIFiles 1_10\ScanFolder\Program.cs:line 84
    


    Many Thanks & Best Regards, Hua Min

    Thursday, May 3, 2018 7:57 AM

Answers

  • "There is no problem to the path."

    Yes there is. Read the error message closely.

     The given path's format is not supported.    at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(Fi

    This is the exact reason your code is failing. You are provide a path that is not valid. This is a data issue that may be caused by how your app is behaving. Is there a particular reason why you don't want to share the path you're using?

    Specifically the call is failing on the Copy call. That means either the source or destination paths are wrong. Putting a breakpoint on that exact line of code and then running it in the debugger will immediately show you which one is bad. Since the source file is @filename which you used earlier in a successful StreamReader call it pretty much has to be the d0 variable. You are manipulating that file name so most likely your manipulation code is wrong. But since we have no way of knowing what the original data was we have no way of knowing how your manipulation code is messing it up.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Jackson_1990 Friday, May 4, 2018 2:34 AM
    Thursday, May 3, 2018 1:53 PM
    Moderator

All replies

  • There's something wrong about your path's format as the error message says. What's your path like?  If it, for example,  contains colons (':') as in this post on stackoverflow you would get that exception.

    wizend

    Thursday, May 3, 2018 8:36 AM
  • Sorry, what to adjust, in above?

    Many Thanks & Best Regards, Hua Min

    Thursday, May 3, 2018 8:52 AM
  • It seems to me, from your StackTrace information, that your parameter 'directoryPath' gets some string value that is not allowed in Windows, for instance a string name that contains special characters.

    wizend

    Thursday, May 3, 2018 9:21 AM
  • There is no problem to the path. What to adjust, due to the error?

    Many Thanks & Best Regards, Hua Min

    Thursday, May 3, 2018 9:39 AM
  • Any other help?

    Many Thanks & Best Regards, Hua Min

    Thursday, May 3, 2018 1:29 PM
  • "There is no problem to the path."

    Yes there is. Read the error message closely.

     The given path's format is not supported.    at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(Fi

    This is the exact reason your code is failing. You are provide a path that is not valid. This is a data issue that may be caused by how your app is behaving. Is there a particular reason why you don't want to share the path you're using?

    Specifically the call is failing on the Copy call. That means either the source or destination paths are wrong. Putting a breakpoint on that exact line of code and then running it in the debugger will immediately show you which one is bad. Since the source file is @filename which you used earlier in a successful StreamReader call it pretty much has to be the d0 variable. You are manipulating that file name so most likely your manipulation code is wrong. But since we have no way of knowing what the original data was we have no way of knowing how your manipulation code is messing it up.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Jackson_1990 Friday, May 4, 2018 2:34 AM
    Thursday, May 3, 2018 1:53 PM
    Moderator