James Steele James Steele - 6 months ago 29
PowerShell Question

powershell- mv file problems when moving file back in path

I am a programming newbie so please stick with me. I am completing Zed Shaw's Learn Python the Hard Way and unfortunately am stuck on a concept in the appendix command line crash course in windows powershell.

My problem is with the move (mv) command, specifically moving a file farther back in the path (hope that makes sense). Here is what I did:

I created a directory called temp, and within that directory created a .txt file called awesome.txt and another dirctory called newplace. Then, I write the command "mv awesome.txt newplace" and the awesome.txt file is moved to the directory newplace. Great! The problem is that I want to move the file awesome.txt back to its original place in the directory temp. When I change my working directory to the directory newplace "cd newplace" and then type "mv awesome.txt temp" the file awesome.txt does not move back to the directory temp, but instead converts from a .txt file to a "file" and stays put in the newplace directory. Any help or explanation would be greatly appreciated!


Folders like this are nested inside each other:


When you cd around, you go into a folder (, e.g. cd temp:

c:\temp\ (o_o)     

And you can only see things in the same folder you are in. So you can move into newplace because that name makes sense where you are. But when you are in newplace

c:\temp\newplace\ (o_o)

You can't move to temp because you don't know where it is. You don't have an index of every directory name on the entire computer that you can shortcut to, you only have two options: something in the same place you are, or something with an absolute path - a full name of where it is. c:\temp\.

So mv awesome.txt temp tries to put it inside temp where you are -> c:\temp\newplace\temp\ -> that doesn't exist, so it assumes you're moving it to a new name in the same place.

You would need mv awesome.txt c:\temp\ to specify it properly.

Except there's a sneaky shortcut, anywhere you are, there is automagically a path called .. which means the folder one <-- thatway from where I am.

So you could mv awesome.txt ..\ to push it back one level in the path, without needing to know exactly where that is. This is probably what Zed Shaw is expecting.