Command Line Crash Course (exercise 12 Windows)

I am doing the exercises in “Command Line Crash Course” from pages 248 to 283 on a Windows 7 laptop. On page 277, under the title “View a File”, I cannot figure out how to copy my file test1.txt that I created on my desktop to my temp file.

When I tried: temp> New-Item test1,txt -type file
all I got was an empty file with that name in temp

When I tried: desktop> cp test1.txt temp/
I got an error message.

When I tried: desktop> cp test1.txt temp
and then: temp> ls
test1.txt does not appear in my list of temp files

When I tried: desktop> more test1.txt
I get a print out of the message that I actually typed into notepad earlier.

When I tried: temp> more test1,txt
I got an error message.

Please tell me how to successfully copy test1.txt with its contents from desktop to the temp file that I have created within my Powershell (Command Line interface).

It looks like you typed:

New-Item test1,txt -type file

But you should have typed:

New-Item test1.txt -type file

Don’t type the -----^ part, that’s just me forcing your eyes to look at that dot. See how you have a comma?

I think that I made the comma mistake (my apologies; I should have been more careful) only when I posted my question in the forum.
Anyway, when I returned to the Command Line Interface (i.e., Powershell) and typed:

cd temp
New-Item test1.txt -type file

I see that test1.txt is included in the temp directory. However, when I then type:

more test1.txt
I get no string (i.e., not the sentence that I actually placed in test1.txt)

However, when I type:

cd desktop
more test1.txt
I see the sentence that I actually typed into test1.txt

I still do not understand how to copy my file test1.txt that I created on my desktop to my temp file so that test1.txt actually contains its text data when it is in the temp file.

Ah, ok so when you went into temp you ran the new-item command. That makes a totally empty file. So, that means everything is working as it should. What I think is the confusion is this chain of events:

  1. You cd Desktop and there’s a file there.
  2. You cd temp, make a new empty file.
  3. You then expect the contents of Desktop/test1.txt to be in the temp/test.txt file.

Those two files are actually in two different places, so they’re totally different. Actually in “a place” isn’t totally accurate, as the two files aren’t really in two directories. Another way to look at this is a file’s real name is the entire path to get to it. So your first file’s name is really C:\Users\you\Desktop\test1.txt and the second file is really C:\Users\you\temp\test1.txt which means they have two totally different names so they’re different files.

So, can you try to explain why you thought this? I think that might help understand and then fix what you think it going on.

This is due probably to my basic misunderstanding of computers, but I just assumed that once a file had a specific name (like “test1.txt”) then it did not matter in which directory it was located; once you requested that file, then you were accessing that file. However, I now stand corrected in my understanding when you point out to me that even though 2 files may share the same exact name, they are not the same files if they are located in 2 different directories.

I finally determined on my own (before I received you last response) to do the following in PowerShell:

cd desktop
mkdir temp

then I opened my text editor (Notepad), wrote my string, chose “File”, then chose “Save As”, chose “desktop” from the window that opened, then chose “temp”, then created the name “test1.txt” in “File name”, and then last of all I hit “Save”.

When I returned to PowerShell, and did the following:

desktop\temp> more test1.txt

I then actually saw the string that I had originally typed into my text editor.

I have completed the exercises 0, 1, 2, and 3 in your book “Learn Python the Hard Way”. I basically created the file “lpthw” in my desktop directory (as I did above with the “temp” file), and then I did the “” file, “” file, and “” file in my Notepad text editor. Everything, so far, has worked fine. However, from the description on page 4 of your book (“Windows: What You Should See”), I get the distinct impression that you are creating the “lpthw” file directly from C:\Users\you so that you get C:\Users\you\lpthw. This is where I get confused. How do you then place your text editor’s newly created file (like “test1.txt”) into the “lpthw” file? When I choose “File” from my text editor and then choose “Save as”, I cannot (for the life of me) find the “lpthw” file unless I place the “lpthw” file in the “desktop” directory.

On windows this is more of a problem than on other systems. Usually you make the file, then when you save it you get a dialog box asking where, then you navigate to the place you want. On windows though, sometimes you have to go up to C:\ then Users then You Then lpthw because they don’t default to just C:\Users\You.

Tell me what text editor and I’ll do some specific instructions.

I am using the Notepad text editor on a Windows 7 laptop.

Ok, you should probably switch to this then:

When you use that, you do a simple Save, then navigate to C:\ then find your user folder, then Desktop and temp should be right there.

That worked!! Thanks so much for your help and your patience with my ineptitude!

Not a problem. Patience with beginners is kind of my thing. :wink:

Hello, i actually are on the same problem. So after reading this discussion, i still have a question. Can you copy a file from Desktop onto temp folder? I still cant realize how to copy C:\Users\You\Desktop\test.txt onto C:\Users\You\temp. I cant find how to move the test.txt file from desktop to temp directory.

I tried doing
You> cd Desktop
Desktop> cp test.txt temp/

and it gives me an error message.

Nvm, i finally copy it.

umm, for anyone who has the same problem with me, you can copy this test.txt file by typing:

Desktop>cp test.txt …/temp

it is double dot/temp, idk why it display three dot on this page tho

Yeah after i went through all this thing, it finally makes sense. You need the “source file location” and “destination file location” to be able to run copy command. And what i actually need is only go back to my working directory first then go to temp directory.

Well, i hope you understand. My english is not good haha