How to create a text list of file names in a directory?

Discussion in 'Mac Basics and Help' started by PkennethV, Mar 21, 2008.

  1. PkennethV macrumors 6502a

    Joined:
    Aug 16, 2006
    Location:
    Toronto
    #1
    I'd like to make a list of DVDs that I have used for storage and the files that each disk contain (probably in Excel). Is there a way that I can *easily* just paste the list of files in each disk into Excel without copying and pasting the name of each file manually?

    thanks, this will save me a lot of time.
     
  2. paleck macrumors 6502a

    paleck

    Joined:
    Apr 11, 2005
    Location:
    with the Tequila!
    #2
    Terminal.App
    cd /to/the/directory/or/disk
    ls(will fit as many as possible on each line) ls -1( will fit one file name per line)

    Hope this helps.
     
  3. killmoms macrumors 68040

    killmoms

    Joined:
    Jun 23, 2003
    Location:
    Washington, DC
  4. PkennethV thread starter macrumors 6502a

    Joined:
    Aug 16, 2006
    Location:
    Toronto
    #4


    thanks...but I'm a complete Terminal noob. Can someone please clarify what i need to change/replace in
    cd /to/the/directory/or/disk
    and where does the "-1" go? Or if you can link me to a page that explains that, that would be helpful too.
     
  5. killmoms macrumors 68040

    killmoms

    Joined:
    Jun 23, 2003
    Location:
    Washington, DC
    #5
    cd is "change directory." It gets you to the path you want. So you need to cd to the folder where you want to list files.

    For instance, if your files were in your Movies folder in your home directory, you'd:

    cd ~/Movies

    ~ is short for the home folder. If they were in a folder called "Movies" on some other drive called "Stuff," you'd:

    cd /Volumes/Stuff/Movies

    Basically that gets you to where your files are.

    Then, ls is the "list" command, and -b is just an operator for it (bare list format, so it only lists file names). The > tells the shell to output the ls's command to a file instead of the screen, and then you put the name of the file, so:

    ls -b > list.txt

    Will create a file called list.txt that lists all the files in that directory, one on each line, just the file name.
     
  6. paleck macrumors 6502a

    paleck

    Joined:
    Apr 11, 2005
    Location:
    with the Tequila!
    #6
    "-1" switch for ls tells ls to only print 1 file per line, which would be useful for an Excel spreadsheet.
     
  7. killmoms macrumors 68040

    killmoms

    Joined:
    Jun 23, 2003
    Location:
    Washington, DC
    #7
    -b also does this when outputting to a file.
     
  8. PkennethV thread starter macrumors 6502a

    Joined:
    Aug 16, 2006
    Location:
    Toronto
    #8
    How to I Change Directory to a DVD? Let's say I have a DVD called My Disk. I've tried
    cd /volumes/My Disk
    and
    cd ~/Desktop/My Disk
    stil doesn't work:eek:
     
  9. paleck macrumors 6502a

    paleck

    Joined:
    Apr 11, 2005
    Location:
    with the Tequila!
    #9
    type ls /Volumes/ that should list all of the currently mounted filesystems it sees. It is probably the name of the disk or something similar
     
  10. killmoms macrumors 68040

    killmoms

    Joined:
    Jun 23, 2003
    Location:
    Washington, DC
    #10
    You cannot have spaces in a path, you have to escape them out. So:

    cd /Volumes/My\ Disk

    That disk doesn't actually live in your desktop, it lives in /Volumes. Your desktop just shows mounted volumes.

    You can also use tab-complete to get to things you're not sure how to type, So, for instance you could type simply:

    cd /Vol

    then hit the tab key, and it'd fill it in to say:

    cd /Volumes

    Then you could add on:

    cd /Volumes/My

    and hit tab, and it'd fill in:

    cd /Volumes/My\ Disk
     
  11. PkennethV thread starter macrumors 6502a

    Joined:
    Aug 16, 2006
    Location:
    Toronto
    #11
    I feel really bad still not being able to do this:eek: I'm now able to cd to the disk. But then obviously when I type in
    -b > list.txt
    it says that I can't make a text file there because the DVD is read-only (duh!). So...how do I change the where the text file will be created (desktop)?
     
  12. beige matchbox macrumors 6502a

    beige matchbox

    Joined:
    Mar 16, 2005
    Location:
    Oxfordshire, UK
    #12
    ls -b > ~/Desktop/list.txt

    That should work i think :)
     
  13. PkennethV thread starter macrumors 6502a

    Joined:
    Aug 16, 2006
    Location:
    Toronto

Share This Page