Results 1 to 4 of 4
Thread: DOS prompt code question
-
2021-01-22, 04:36 PM (ISO 8601)
- Join Date
- Jan 2009
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
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
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.
-
2021-01-22, 06:24 PM (ISO 8601)
- Join Date
- Nov 2006
- Location
- England. Ish.
- Gender
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
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
-
2021-01-25, 01:32 PM (ISO 8601)
- Join Date
- Jan 2009
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";
Last edited by JeenLeen; 2021-01-25 at 01:44 PM.
-
2021-01-25, 03:54 PM (ISO 8601)
- Join Date
- Nov 2006
- Location
- England. Ish.
- Gender
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