1

I'm using CS-Script to compile it, and it compiled fine after I fixed all the syntax errors. I compiled it to a console application executable.

Unhandled Exception: System.NotSupportedException: 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 MainClass.Main(String[] argv)

I already searched through a few threads and tried a few things, and it didn't work.

    string ws = @"C:\Users\Computer 1\Desktop\Workspace2";
    string tech = @"C:\Users\Computer 1\Desktop\Tech Photos";
    string des = @"C:\Users\Computer 1\Desktop\Final";
    List<string> branches = new List<string>(Directory.GetDirectories(tech));
    branches = branches.Select(b => b.Substring(0,3)).ToList();
    string[] dirs = Directory.GetDirectories(ws);
    string[][] imgs = new string[dirs.Length][];

    for (int i = 0; i < dirs.Length; i++)
    {
        imgs[i] = Directory.GetFiles(dirs[i]);
        Array.Sort(imgs[i]);
        imgs[i].Reverse();
        string newDir = Path.Combine(des, String.Concat(branches[i], " Tech Pics"));
        Directory.CreateDirectory(newDir);
        foreach (string f in imgs[i])
        {
            List<string> words = new List<string>(f.Split(' ', '_', '-'));
            string s = branches[i] + " - ";
            foreach (string w in words)
            {
                if(Char.IsUpper(w[0]) && Char.IsLower(w[w.Length - 1]))
                    s += " " + w;
            }

            s += s.Length > 6 ? "" : "(NAMELESS) - " + i.ToString();
            s += Path.GetExtension(f);
            File.Copy(f, Path.Combine(newDir, s));
        }
    }

This program is for automatically looking through a bunch of files and renaming them in a more appropriate format. It compiles fine, but I can't get past this exception.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ZJohnsonPest
  • 11
  • 1
  • 3
  • Can you open it up in VS and use the debugger to see which path is causing the exception? – stelioslogothetis May 12 '17 at 19:02
  • Debug your program... look at the line the error is occur and what the file path is. Once you've done that if you can't figure it out post, the filename and the line it's occuring at – johnny 5 May 12 '17 at 19:02
  • Looking at your code, i cannot spot something wrong. Not sure if the error is specific to executing it with cs-script. If it is, you could try writing the content of `f` and `Path.Combine(newDir,s)` to the console before calling `File.Copy(...)` and run the script with cs-script again. What is the content of the variables when the error occurs? –  May 12 '17 at 19:03

0 Answers0