Link to home
Create AccountLog in
Avatar of NSM_Superman
NSM_SupermanFlag for United States of America

asked on

Need a batch file/vb script to output the owners of all files on a fileshare into a textfile

I am looking for a batch file or a vb script that will output the owner of a folder into a text file. we have a file share that has become a dumping ground for all users in the company and we need to get it cleaned up but before we can do that, we need to contact the users who have created this mess rather than rely on them to clean it up themselves.

i have checked online and have found interesting solutions but none that do exactly what i need. is this even possible?
Avatar of forrestoff
forrestoff

You should be able to import the output of this into an excel spreadsheet and modify to your liking.  It will enumerate the directory tree and show the owner along with the directory.
rem @echo off
dir/s/b/ad >dirlist
if EXIST ownership.txt del ownership.txt
for /f "tokens=*" %%a in (dirlist) do for /f "skip=3 usebackq tokens=1,2,3,4,5,6,7" %%i in (`dir/ad/q "%%a"`) do @echo %%m %%n >>ownership.txt
del dirlist

Open in new window

Avatar of NSM_Superman

ASKER

ok that runs and gives me an output of all the files for the directory i fun it for, but i need it to show not only that but the owner or creator of all the folders listed
Sorry--this worked for me because I have spaces in my directory path. Let me make it more robust.
Okay.  Just like first one, this does enumerate the directory tree (i.e. displays no files via the "/ad" switch on the dir command).

Just copy and paste the command in the root of your directory tree, and open the output.txt file in excel or similar.  In the output.txt the output should be the form of the following:

<owner name> <directory>

Note that this will also include the pesky . and .. directories too.  In excel you should be able to Find and Replace all \. and \.. entries with blank ones.  Then sort by the username (column 1).

for /f "usebackq tokens=*" %i in (`dir/s/b/ad`) do for /f "skip=5 usebackq tokens=1,2,3,4,5,6,7" %a in (`dir/ad/q %~si`) do @echo %e %~si\%f>>output.txt

Open in new window

dude, that worked tremendously! thank you so much.
but one more question, is there a way to add the last date accessed or last date modified on there as well?
ASKER CERTIFIED SOLUTION
Avatar of forrestoff
forrestoff

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Check out this command:  dir /Q