Batch program:Get name and owner in a Report output (csv ,txt) of a file that contains another files and documents

142 Views Asked by At

I am trying to print the name and the owner of a files and documents that are inside a file .I've almost already got that but the output format are very bad I need only the name and the owner I want obtain this in separated columns with labels if is possible.

I tried with this code

@ECHO OFF
DIR  "C:\Users\user\Desktop\prueba" /q  >"C:\Temp\output.txt"

but the name and the owner are very close and I cant obtain the space to get a better report.

1

There are 1 best solutions below

0
CristiFati On

Here's of batch script (it's ugly, I consider it a workaround) that I think it does what you need. Note that I tested it on Win10, for versions older than Win7/2008 (most likely) the script should be adjusted (because of the different dir command output):

@echo off

set _FOLDER=C:\Users\user\Desktop\prueba
set _OUT_FILE=C:\Temp\output.txt
echo Owner Name > "%_OUT_FILE%"

for /f "tokens=*" %%f in ('dir /a-d /b %_FOLDER%\*') do (
    for /f "tokens=4*" %%g in ('dir /q "%_FOLDER%\%%f" ^| findstr /e "%%f"') do (
        echo %%h >> "%_OUT_FILE%"
    )
)