WMIC Command For File Attributes

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

WMIC Command For File Attributes

Post by jstevens »

I am looking for a batch file solution to recurse through each directory and write (append) file attributes to a flat file utilizing the WMIC command.

WMIC DataFile /? to check if functionality exists.

I'm interested in wmic datafile where name="c:\\Some\\Path\\SomeFile.xls" GET Name,Destination,Path,FileType,LastModified > output.txt

Thanks for your suggestions.
Regards,
John

User avatar
HansV
Administrator
Posts: 78439
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WMIC Command For File Attributes

Post by HansV »

You may have better luck in Microsoft's scripting forum.
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: WMIC Command For File Attributes

Post by John Gray »

Why would you want to use WMIC (the most unfriendly user output I have ever come across) when you can use an ordinary uncontaminated BATch file? :evilgrin:

Here is some output from my informational BATch file, applied to itself...

Code: Select all

BATch PARAMETER EXPANSIONS (W2K, XP, W7, W10 ...)

how the BATch file was invoked      %0       batparms
BATch file without double-quotes    %~0      batparms
  *** all below is converted to UPPER CASE...
fully qualified file path-name      %~f0     I:\Dropbox\BAT\BATparms.bat
drive letter plus colon             %~d0     I:
path                                %~p0     \Dropbox\BAT\
drive letter and path               %~dp0    I:\Dropbox\BAT\
file path without extension         %~dpn0   I:\Dropbox\BAT\BATparms
file name                           %~n0     BATparms
dot plus file extension             %~x0     .bat
file name and extension             %~nx0    BATparms.bat
fully-qualified short-name path     %~fs0    I:\Dropbox\BAT\BATparms.bat
path with short names only          %~s0     I:\Dropbox\BAT\BATparms.bat
file attributes                     %~a0     --a------
file date and time (local format)   %~t0     07/12/2017 08:12
size of file                        %~z0     2734

combined DIR-like information       %~fatz0
--a------ 07/12/2017 08:12 2734 I:\Dropbox\BAT\BATparms.bat
(always produced in the order: a,t,z,f)
[/b]
Is any of the above what you might want?

PS Note to Administrators - why can't "code" be produced in Bold Black, rather than Weedy Green? :scratch: :hairout:
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78439
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WMIC Command For File Attributes

Post by HansV »

It's an attempt to make the world a little bit greener...
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: WMIC Command For File Attributes

Post by John Gray »

Here's a quick BATch file to produce something like what you might want:

@echo off
setlocal
:: our log file
set log=%~n0.txt
if exist %log% del %log%
:: the target top-level folder
:: ....V-------------V
for /r c:\windows\logs %%a in (*.*) do call :process "%%a"
start "" notepad %log%
endlocal
exit /b 0
::----------
:process
echo %~fatz1 >> %log%
goto :eof


and its output....

--a------ 19/12/2017 08:49 6113218 c:\Windows\Logs\CBS\CBS.log
--a------ 14/09/2017 07:21 2894775 c:\Windows\Logs\CBS\CbsPersist_20170914075248.cab
--a------ 11/10/2017 03:22 3234349 c:\Windows\Logs\CBS\CbsPersist_20171011034035.cab
--a------ 12/10/2017 07:20 2851756 c:\Windows\Logs\CBS\CbsPersist_20171012074006.cab
--a------ 15/11/2017 06:51 660201 c:\Windows\Logs\CBS\CbsPersist_20171115121442.cab
--a------ 16/11/2017 08:27 2840091 c:\Windows\Logs\CBS\CbsPersist_20171116085241.cab
--a------ 17/03/2017 06:05 1523067 c:\Windows\Logs\DISM\dism.log
--a------ 15/11/2017 06:44 43549 c:\Windows\Logs\DPX\setupact.log
--a------ 24/03/2016 08:05 0 c:\Windows\Logs\DPX\setuperr.log
--a--c--- 20/11/2017 07:10 786432 c:\Windows\Logs\RecoveryDisc\RecoveryDisc.0.etl
--a--c--- 20/11/2017 07:09 720896 c:\Windows\Logs\RecoveryDisc\RecoveryDisc.1.etl
--a--c--- 20/11/2017 07:06 917504 c:\Windows\Logs\RecoveryDisc\RecoveryDisc.2.etl
--a--c--- 07/06/2015 11:18 3670016 c:\Windows\Logs\WindowsBackup\SystemImage.1.etl
--a--c--- 27/05/2015 11:15 2686976 c:\Windows\Logs\WindowsBackup\SystemImage.2.etl
--a--c--- 27/05/2015 11:13 4063232 c:\Windows\Logs\WindowsBackup\SystemImage.3.etl
--a--c--- 25/05/2015 12:29 2686976 c:\Windows\Logs\WindowsBackup\SystemImage.4.etl
--a--c--- 24/11/2015 07:18 3145728 c:\Windows\Logs\WindowsBackup\SystemImage.etl
--a------ 12/11/2017 08:09 2078720 c:\Windows\Logs\WindowsBackup\Wbadmin.0.etl
--a--c--- 17/03/2017 06:37 1935360 c:\Windows\Logs\WindowsBackup\Wbadmin.1.etl
--a--c--- 24/02/2017 07:25 102400 c:\Windows\Logs\WindowsBackup\Wbadmin.2.etl
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: WMIC Command For File Attributes

Post by jstevens »

John,

I have tried your suggestion and it will work for me. Is it possible to exclude certain folders? I have a good number of them that I would like to exclude and I'm not sure how to incorporate the list. Perhaps the code can read a flat file containing the list of folder names to exclude.
Regards,
John

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: WMIC Command For File Attributes

Post by John Gray »

Yes, it would be possible to exclude certain folders but only by testing every file path passed to the :process subroutine against every one of the folder names (well, not quite every folder name, probably just half of them). The more exclusions there are, the longer it will take!
By sorting the excluded folder names into alphabetical order, it could be made more sophisticated.

A simpler method might be to run the BATch file more or less 'as is' and edit the presumably-sorted output to remove all the files in 'want to exclude' folders. I suspect this would be quicker for a 'one-off' requirement!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: WMIC Command For File Attributes

Post by jstevens »

John,

I'll tinker with your suggestion. I have a number of VMs where the code is trying to read each and every band.

Thanks again.
Regards,
John