0

I am attempting to use the code found in the answer here: Directory.Move doesn't work (file already exist)

This is exactly the method I need, but when I try to add it to my code, the line

Directory.CreateDirectory(folders.Target);

has the word "Target" underlined in red, and the error is "'object' does not contain a definition for 'Target' and no extension method 'Target' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)"

Can anyone help me get rid of that error?

Community
  • 1
  • 1
Jake
  • 3,142
  • 4
  • 30
  • 48
  • Matteo - but it should, since folders is defined as the output of a stack, whose input was an object of type Folders, which does have that property defined – Jake Jun 15 '12 at 17:14
  • 3
    The error message seems pretty clear - you presumably haven't declared `folders` as being of type `Folders`, given that it's complaining about `object` not containing `Target`... – Jon Skeet Jun 15 '12 at 17:15
  • As per Claudio's comment below, you're correct, but what I was trying to do was modify the declaration of `folders`, when instead the solution was to modify the declaration of the stack from which `folders` gets its definition. Thank you! – Jake Jun 15 '12 at 17:18
  • Next time you ask a question, you should give much more context - see http://tinyurl.com/so-hints. – Jon Skeet Jun 15 '12 at 17:22
  • You should better change your title to describe your problem. – chaliasos Jun 15 '12 at 17:24
  • Thanks for the constructive criticism. What more context would have been helpful in my case specifically? I didn't add much since essentially my question was "I put in this code, but it didn't work and I don't know why". I'd like to know what I can do to be a better Stack user! – Jake Jun 15 '12 at 17:24

2 Answers2

1

Try changing Stack by Stack<Folders>

var stack = new StackStack<Folders>();
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
  • Works perfectly, thanks! Did you just edit the answer in the original question? I tried but it was already there in the edit window =) I'll accept your answer as soon as the timer goes down – Jake Jun 15 '12 at 17:16
  • I've edited it now. It already actually had the generics in the source, but the answer was using HTML tags for the code instead of the markdown approach :( – Jon Skeet Jun 15 '12 at 17:22
0

Folders.Target is defined in this class

public class Folders
{
    public string Source { get; private set; }
    public string Target { get; private set; }

    public Folders(string source, string target)
    {
        Source = source;
        Target = target;
    }
}
kenwarner
  • 28,650
  • 28
  • 130
  • 173
  • Yeah, I have that code in there as well, it still doesn't like it though, perhaps because 'folders' is a var and not a member of Folders? – Jake Jun 15 '12 at 17:14
  • @user774359 is 'folders' being assigned in the same manner? Can you post more of your code? – BryanJ Jun 15 '12 at 17:17
  • My code was exactly what is available on this link: http://stackoverflow.com/questions/2553008/directory-move-doesnt-work-file-already-exist, as the first answer. I was just trying to implement it in my particular project, but was receiving an error. – Jake Jun 15 '12 at 17:19