1

I am trying to move a file but I can only get it working when its to a special folder and not a folder within a special folder.

In case I would like to move it to a folder call "i" located within my documents:

foreach (string filename in Directory.GetFiles(MainPath))
        {

            var info = new FileInfo(filename);
            if (info.Length < 1000000)
            {
                File.Move(filename, System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),info.Name));
            }
        }
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Code
  • 39
  • 7
  • 1
    cw your second parameter (path). Let's see what you're setting the path as – FirebladeDan Aug 19 '15 at 20:44
  • sorry i dont know what that means, right now the path is to my documents but i want it to my documents/ i. whenever i try fix it i get errors – Code Aug 19 '15 at 20:47
  • @FirebladeDan -- yeah, I agree -- your comment makes no sense. – rory.ap Aug 19 '15 at 20:48
  • What I mean is print out the System.IO.Path... so you can see where it is moving it. it should read C:\documents\filename. I have a feeling its breaking on the combine maybe losing the backslash – FirebladeDan Aug 19 '15 at 20:48
  • @roryap - type cw then hit tab tab on your keyboard in vs. shortcut chief: cw +tab +tab = Console.Writeline() – FirebladeDan Aug 19 '15 at 20:49
  • i can never run it to see the path. if i try make a variable as the correct path and use it, it will just give me errors – Code Aug 19 '15 at 20:50
  • What does "special folder" mean? What's special about that folder, or is it just unfortunate phrasing? – MarsAtomic Aug 19 '15 at 21:09
  • special folder is used to refer to windows folders such as my documents or my pictures without having to write out the whole path which might not work on different os or other peoples computers – Code Aug 19 '15 at 21:11

2 Answers2

0

Would this work? If you want to have a folder named "i" beneath the current folder (e.g. your documents), just add it to the call to Path.Combine().

File.Move(filename, System.IO.Path.Combine(
    System.Environment.GetFolderPath(
    Environment.SpecialFolder.MyDocuments), "i", info.Name));
rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • tried that, it says "no overload for method ocmbine takes 3 arguments" – Code Aug 19 '15 at 20:46
  • What version of .NET? If you're using 2.0, you're out of luck. Anything later than that, it should work. If you're using 2.0, you should definitely upgrade; it's seriously out of date. – rory.ap Aug 19 '15 at 20:47
  • im using 3.5 only because i want it to run on winxp. – Code Aug 19 '15 at 20:51
0
Console.WriteLine(System.IO.Path.Combine
(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),info.Name)));

What does this show?

FirebladeDan
  • 1,069
  • 6
  • 14
  • oh now i see what you mean, but when i put that in and run it, the output box doesnt show anything. i also tried a messagebox and the same thing happens. i think its because its in a for loop – Code Aug 19 '15 at 20:57
  • i got it, it shows this C:\Users\William\Documents\IMG_1255.jpg – Code Aug 19 '15 at 21:03