Support the GITP forums on Patreon
Help support GITP's forums (and ongoing server maintenance) via Patreon
Results 1 to 4 of 4
  1. - Top - End - #1
    Ettin in the Playground
     
    BardGuy

    Join Date
    Jan 2009

    Default DOS prompt code question

    I'm trying to use DOS code to pipe the full directory path (with metadata) to a text file, such that one line of data has
    -creation date
    -size
    -file path
    -file name

    I can get the metadata by using
    dir *.* /s > files.txt
    It yields most of the data I want in a single row like
    Code:
    09/21/2020  05:12 PM            39,758 P2021 draft file.csv
    But note that the above doesn't have the file path. I'd have to get that from a few rows above... which seems tricky to do programmatically.

    I can get the full filepath by using
    dir *.* /b /s > files.txt;
    But that excludes the metadata
    Code:
    R:\subfolder\P2021 draft file.csv
    Does anyone know the right combination of DOS options to get both the full filepath and the metadata, such that I could get something like
    Code:
    09/21/2020  05:12 PM            39,758 r:\subfolder\P2021 draft file.csv


    EDIT
    A technicality: I'm actually running this within SAS, but it should work the same as in DOS, with the possible exception of when single/double-quotes are needed around file names. I'm using the X system option to issue a command to the operating system.
    Last edited by JeenLeen; 2021-01-22 at 04:47 PM.

  2. - Top - End - #2
    Ogre in the Playground
     
    Flumph

    Join Date
    Nov 2006
    Location
    Essex, England
    Gender
    Male

    Default Re: DOS prompt code question

    Code:
    del x.txt
    echo off
    FOR /R . %F IN (*.*) DO echo %~tF %~zF %~F >>x.txt
    echo on
    type x.txt
    You will need the echo off, otherwise the echo commands will appear in the output file. If you can only issue one command then put all the commands in a batch file and run that.

    Results:
    Code:
    C:\Mine\Music>del x.txt
    
    C:\Mine\Music>echo off
    FOR /R . %F IN (*.*) DO echo %~tF %~zF %~F >>x.txt
    echo on
    
    C:\Mine\Music>type x.txt
    30/09/2012 16:50 4035438 C:\Mine\Music\Best of Anime reduced\07 Track 07.mp3
    30/09/2012 16:53 4958084 C:\Mine\Music\Best of Anime reduced\11 Track 11.mp3
    30/09/2012 16:54 5108027 C:\Mine\Music\Best of Anime reduced\13 Track 13.mp3
    30/09/2012 16:54 3305578 C:\Mine\Music\Best of Anime reduced\14 Track 14.mp3
    07/05/2016 14:15 3745108 C:\Mine\Music\Fleetwood Mac - The Dance\01 - Track 1.mp3
    07/05/2016 14:15 3357346 C:\Mine\Music\Fleetwood Mac - The Dance\02 - Track 2.mp3
    07/05/2016 14:16 2510038 C:\Mine\Music\Fleetwood Mac - The Dance\03 - Track 3.mp3
    07/05/2016 14:16 4906512 C:\Mine\Music\Fleetwood Mac - The Dance\04 - Track 4.mp3
    Last edited by Manga Shoggoth; 2021-01-22 at 06:43 PM.
    Warning: This posting may contain wit, wisdom, pathos, irony, satire, sarcasm and puns. And traces of nut.

    "The main skill of a good ruler seems to be not preventing the conflagrations but rather keeping them contained enough they rate more as campfires." Rogar Demonblud

    "Hold on just a d*** second. UK has spam callers that try to get you to buy conservatories?!? Even y'alls spammers are higher class than ours!" Peelee

  3. - Top - End - #3
    Ettin in the Playground
     
    BardGuy

    Join Date
    Jan 2009

    Default Re: DOS prompt code question

    Thank you!

    For my own records and anyone else looking, here's how to do it in SAS, assuming XCMD is enabled
    Code:
    OPTIONS NOXWAIT;
    %let dir=R:\&subfolder;
    X "cd &dir";
    X "echo off";
    X "FOR /R . %F IN (*.*) DO echo %~tF %~zF %~F >> files.txt";
    X "echo on";
    %F does yield a warning about macro resolution, as %F is SAS code for "call the macro named F"... but as long as you don't have a macro named F, it works fine.
    Last edited by JeenLeen; 2021-01-25 at 01:44 PM.

  4. - Top - End - #4
    Ogre in the Playground
     
    Flumph

    Join Date
    Nov 2006
    Location
    Essex, England
    Gender
    Male

    Default Re: DOS prompt code question

    You're welcome.

    The F is arbitary, so you can use a different letter if you need to, in which case all the %...F elements change to something else.
    Warning: This posting may contain wit, wisdom, pathos, irony, satire, sarcasm and puns. And traces of nut.

    "The main skill of a good ruler seems to be not preventing the conflagrations but rather keeping them contained enough they rate more as campfires." Rogar Demonblud

    "Hold on just a d*** second. UK has spam callers that try to get you to buy conservatories?!? Even y'alls spammers are higher class than ours!" Peelee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •