Using command prompt

Discussion in 'A+' started by Dhughes, Jun 26, 2007.

  1. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    Guys im having a bit of confusion with > , >> ,< in the command prompt,

    > firstly ,

    this command sends the output from a command into a text file, it either over writes a text file you name or makes a new one if one isnt already present

    Ive put some photos in a folder on my desktop which i have called Test1, when i command "dir desktop\Test1 i get the list of the files in there, so when i type "dir desktop\Test1>Test1.txt" the list which i saw in the above command should be saved to a file called Test1.txt, i dont have one so this should be created automatic.

    All that happens when i press return is the next new command line appears awaiting for a command and there's no new files in the folder Test1.

    What am i doning wrong? or am i looking in the wrong place for the new .txt file?
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  2. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    desktop directory normally comes under:

    Code:
    c:\Documents and Settings\nameofuser\Desktop
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  3. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    yeah sorry ive got all that in the command line, i was just show this bits i had typed in, but where is the file saved too?
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  4. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    Which directory are you running the command from?
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  5. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    desktop

    mywhole command line reads....

    c:\Documents and Settings\david>dir desktop\Test1>Test1.txt
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  6. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    try this run it from the test1 directory:

    Code:
    dir > test1.txt 
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  7. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    sorry mate , how do i get to run that straight from the Test1 directory? Feeling really thick here at the mo
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  8. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    Ive just done... cd desktop\Test1

    so now my commant line reads ....

    c:\Documents and Settings\david\desktop\Test1>


    but then when i do dir Test1.txt

    file not found
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  9. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    you need to do:

    Code:
    dir > test1.txt
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  10. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    You my wierdybeard wizard friend are bleeming mavellous!!!!!

    Thankyou!
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  11. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    The bill is in the post :wink: :D
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  12. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    The key thing here is that you gave the output filename without any path. This means that the file will be created in your *current* directory.

    If you want it to go elsewhere then you need to give the path as part of the filename.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  13. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    You need to type in the command 'dir /x' to get the mangled folder names, so 'C:\documents and settings\' becomes 'C:\docu~1\' for example, so you would type:

    C:> dir C:\docu~1 > Test1.txt

    to redirect the current documents and setting dir listing to the text file Test1.txt.

    Expand on this principle to do the same with other folders.
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  14. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    what all the way form the C: ?
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  15. Dhughes

    Dhughes Byte Poster

    161
    4
    27

    sorry mate you lost me well and good,
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  16. wizard

    wizard Petabyte Poster

    5,767
    42
    174
    Not in XP, it supports 256 character path names so you don't have ~ anymore
     
    Certifications: SIA DS Licence
    WIP: A+ 2009
  17. Dhughes

    Dhughes Byte Poster

    161
    4
    27



    what all the way form the C: ?
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  18. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    OK - two points here - mangled file names and paths.

    IMHO - the reference to mangled names is a red-herring here.
    However - you need to know about them because they are a legacy thing, and may pop up in the exam.

    These days path and filenames can be long, and can contain spaces. In the old days filenames were 8 chars, a dot, and 3 chars. In most versions of Windows a short (and mangled) name is kept along with the full name. The mangling is usualy done by truncating the full name and using a ~ and a number at the end of the 8 characters. So "Documents and Settings" might be mangled as DOCUME~1. Note that I used "" around the long name. If a long name has spaces in it then you must do that for the system to recognize it!

    Paths. Look in the book for descriptions of 'absolute' paths and 'relative' paths.

    An absolute path might be C:\Archives\bin
    A relative path might be ..\bin

    The difference is whether there is a \ at the start of the path (after any drive letter). You can think of it as directions on how to walk to a file.

    So when I said that you had to give a path name for the redirect - it doesn't *have* to start with C:, it could be a relative path.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  19. Dhughes

    Dhughes Byte Poster

    161
    4
    27
    so if i have a second folder on my desktop called Test2 please could you show me the what youd type to copy the contents list from Test1 into the folder Test2

    Take it im already in the Test1 directory
     
    Certifications: A+ Essentails, A+ Technician , MCDST
    WIP: MCSE
  20. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    dir > ..\Test2

    Explanation: You are in Test1, so dir will show the contents of Test1. To get to Test2 you could CD to the parent directory (desktop) with CD .. and then CD to Test2 with CD Test2. So the *relative* path is ..\Test2.

    You could also give an absolute path, which would look something like: c:\Documents and Settings\david\desktop\Test2 but note there are spaces in there - so the command would be:
    dir > "c:\Documents and Settings\david\desktop\Test2"

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.