Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Would Like a "Simple" Batch file, I think...  (Read 4058 times)

0 Members and 1 Guest are viewing this topic.

iONik

    Topic Starter


    Beginner

    Would Like a "Simple" Batch file, I think...
    « on: March 28, 2010, 11:23:43 AM »
    Can't find a way to create a text file of all files on a drive sorted by Dir, sub dir.. with attributes.
    It seems simple, but I am not getting it!

    Can anyone help?

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Would Like a "Simple" Batch file, I think...
    « Reply #1 on: March 28, 2010, 01:18:15 PM »
    This little snippet may help:

    Code: [Select]
    @echo off
    for /f "tokens=*" %%i in ('dir /s /b /a d:\') do (
      attrib "%%i" >> dir.txt


    Be sure to change the drive letter in the dir command and you might want to add path information to the output file (dir.txt)

    Good luck.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    iONik

      Topic Starter


      Beginner

      Re: Would Like a "Simple" Batch file, I think...
      « Reply #2 on: March 28, 2010, 01:44:14 PM »
      This is what I am using:
      Code: [Select]
      @echo off
      for /f "tokens=*" %%i in ('c: /s /b /a d:\') do (
        attrib "%%i" >> c:\dir.txt

      notepad c:\dir.txt

      and I get a blank notepad doc.

      Thus, It doesn't seem to be working for me.


      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Would Like a "Simple" Batch file, I think...
      « Reply #3 on: March 28, 2010, 01:49:23 PM »
      hmm...

      tree /f does everything you want except showing attributes.
      I was trying to dereference Null Pointers before it was cool.

      Salmon Trout

      • Guest
      Re: Would Like a "Simple" Batch file, I think...
      « Reply #4 on: March 28, 2010, 02:24:11 PM »
      @echo off
      del d:\dir.txt
      for /f "tokens=*" %%i in ('dir /s /b /a /a-d d:\') do (
        attrib "%%i" >> d:\dir.txt



      small part of output file...

      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\87012.avi
      A            D:\Multimedia\Rail Videos\DVD-1\avi\90 [pal-vcd][mpeg2video][mp2].mpg
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\90.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\90024-tpo-rugby.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\90029-tpo-rugby.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\91119-snow-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\d9000_1.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\d9000_2.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\d9000_3.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\d9016-cw.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\d9016.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\deltic-firestarter-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\e-star_rescue.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\gn-cannons.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\grice-deltics-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\kings_cross.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\lickey-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\pendolino_euston_h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\pendolino_euston_walkthro_h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\run1_10-23.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\run3_11-29.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\run4_11-47.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\run8_14-20.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\serco-spoonz.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\spanish_inquis-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\spinnin_state_iv-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\spin_doctor_nuneaton-h.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\uosa.avi
      A    R       D:\Multimedia\Rail Videos\DVD-1\avi\welham_green.avi
      A            D:\Multimedia\Rail Videos\flv\2-Rickmansworth to Amersham driver pov.flv

      iONik

        Topic Starter


        Beginner

        Re: Would Like a "Simple" Batch file, I think...
        « Reply #5 on: March 28, 2010, 02:46:15 PM »
        Yes silly me changed "dir" to "c:".  It works great... Thanks all.

        Solved

        Salmon Trout

        • Guest
        Re: Would Like a "Simple" Batch file, I think...
        « Reply #6 on: March 28, 2010, 02:50:06 PM »
        Alternative, better attribute info by using %%~a variable modifier to get a 9 char attribute string, explanation below,

        Code: [Select]
        @echo off
        del d:\dir.txt
        for /f "tokens=*" %%i in ('dir /s /b /a d:\') do (
          echo %%~ai %%~dpnxi >> d:\dir.txt
         ) 


        Code: [Select]
        d--hs---- d:\$RECYCLE.BIN
        --a------ d:\msdia80.dll
        dr-h----- d:\MSOCache
        d-------- d:\Multimedia
        d-------- d:\Sandbox
        d-------- d:\sieve
        d--hs---- d:\System Volume Information
        d-------- d:\templogs
        d-------- d:\Tempvu
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1001
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1002
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1017
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-500
        d--hs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-501
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$I4LZW3U.srt
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$I5OT8XX.nfo
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$IBD8E95.zip
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$IBRM3TZ.nfo
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$IGILP8T.txt
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$IIKWE2S.exe
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$IM079V9.rar
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$R4LZW3U.srt
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$R5OT8XX.nfo
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$RBD8E95.zip
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$RBRM3TZ.nfo
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$RGILP8T.txt
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$RIKWE2S.exe
        --a------ d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\$RM079V9.rar
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1000\desktop.ini
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1001\desktop.ini
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1002\desktop.ini
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-1017\desktop.ini
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-500\desktop.ini
        --ahs---- d:\$RECYCLE.BIN\S-1-5-21-2475452901-1092781832-1925167435-501\desktop.ini
        dr------- d:\MSOCache\All Users
        dr------- d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9
        d-------- d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9\FILES
        --a------ d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9\PRO11.MSI
        --a------ d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9\SKU011.XML
        d-------- d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9\FILES\PFILES
        d-------- d:\MSOCache\All Users\90000409-6000-11D3-8CFE-0150048383C9\FILES\SETUP

        Code: [Select]
        attrib string has 9 characters

        each character is either a letter if the attribute is YES or a - symbol if attribute is NO
        their meanings:

        123456789
        drahscotl

        1 d=is a directory
        2 r=is read only
        3 a=has archive bit set
        4 h=is a hidden file
        5 s=is a system file
        6 c=is a compressed file
        7 o=is an offline file
        8 t=is a temporary file
        9 l=is a link (junction point)

        « Last Edit: March 28, 2010, 03:48:33 PM by Salmon Trout »

        Salmon Trout

        • Guest
        Re: Would Like a "Simple" Batch file, I think...
        « Reply #7 on: March 29, 2010, 12:07:12 AM »
        note that in 4,5 and 6 'file' should read 'file or directory', possibly 7 and 8 too