Advice to catalog all .doc files in all directories except a few

(imported topic written by JamesN91)

I’ve used this thread and successfully was able to catalog all *.doc files on test computer using a DIR command.

http://forum.bigfix.com/viewtopic.php?id=362

note- For win xp machines

I do have some issues.

  1. I want to search all directories EXCEPT the Document and Settings directory. Any idea?

  2. What would be the best way to capture all .doc file attributes such as size and creation date into a big fix report?

The end goal is to have a inventory / catalog of all Doc files on the workstation into a manageable report that contains path, file name, file size,and file creation date per workstation in the environment.

Thank you in advance. I am new to big fix so please pardon some of my beginner questions.

(imported comment written by BenKus)

Hi James,

Welcome to the forum… Can you post the relevance from your property definition? (I am not sure which version you used)…

Ben

(imported comment written by SystemAdmin)

(In reponse to your first question)

If what you are doing is based on Brolly’s reponse in reply #19 you can just change the basic command from ‘Dir’ to one which is based on a FOR loop which includes a filter for the directory you want to exclude.

Original action line:

runhidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.MP3 >"{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt"

Suggestion:

runhidden {pathname of system folder}\cmd.exe /C FOR /d %n in (c:) DO @IF “%n”==“c:\Documents and Settings” ("") ELSE DIR /s /b c:.MP3 >"{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt"

(imported comment written by JamesN91)

runhidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.MP3 >"{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt"

Yes, this is what I’m doing.

I will give the FOR loop a try and see if that meets my needs. Thanks for the guidance! I did not think to go that route.

Along the same lines but seperate question, I have the need to search for 1 particular file. I have the file name. I need to search all drives including attached USB drives at time of scan. What would be the best course of action?

(imported comment written by JamesN91)

Here is what I have…

FOR /d %n in (c:*) DO @IF “%n”==“c:\Documents and Settings” ("") ELSE DIR /s /TA c:\ *.txt, *.doc, *.docx, *.docm, *.dotm, *.xls, *.xlsx, *.xlsm, *.xlsb, *.xlam, *.pptx, *.pptx, *.potx, *.potm, *.ppam, *.ppsx, *.ppsm, *.accdb, *.accde, *.accdt, *.accdr, *.mdb, *.ppt, *.pdf, *.zip | FIND “/” > c:\windows\temp\docs.txt

That gives me this sample output into the docs.txt file…

##RESULTS##

01/15/2010 01:34 PM 6,363 test.txt

Here’s the problem… I have creation date, Last Access Time, Size, and File name… but I need file path too. I’m struggling to find a 1 liner way of doing it.

/b gives path but no size/date

/s gives time/size but no path

Below is my goal assuming test.txt is located in c:\temp

##GOAL##

01/15/2010 01:34 PM 6,363 c:\temp\test.txt

Any other suggestions?

(imported comment written by BenKus)

How about this:

// get the list of the files and their paths
parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt"
waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.MP3 >”{parameter “outputfile”}"

// go through the list in relevance to remove docs and settings and look up size/dates
appendfile {concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " & (size of file(it) as string) & " – " & it ) else nothings) of lines whose (it as lowercase does not contain “documents and settings”) of file (parameter “outputfile”)}

// replace the output file with the new file
delete "{parameter “outputfile”}"
move __appendfile “{parameter “outputfile”}”

Ben

(imported comment written by JamesN91)

That’s slick the way that your doing it. I never thought of using concantenate to append the time/size to a txt file.

Using that method I’m getting an error though…

METHOD

  1. Created small test group. Assigned 2 computers to it.

  2. Within test group create new action.

  3. Within Action scrip added below…

CODE

// get the list of the files and their paths TEST3

parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\Docs.txt”

waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.txt >"{parameter “outputfile”}"

// go through the list in relevance to remove docs and settings and look up size/dates

concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " & (size of file(it) as string) & " – " & it ) else nothings) of lines whose (it as lowercase does not contain “documents and settings”) of file “{parameter “outputfile”}”

ERROR

“Unknown action command line 5”

Thank you in advance for the help. I’m digging through the manual also looking for the action script error.

(imported comment written by NoahSalzman)

Don’t put the “concatenation “%0d%0a” of …” relevance in the Action Script, that part is supposed to go in a separate Analysis (Ben did not state that explicitly).

The idea is:

  1. Have an ActionScript task create the outputfile on each computer

  2. Haven a separate Analysis use relevance to read the contents of that file and display the results in the BigFix Console

Or, at least, that is what I understood his post to mean… :slight_smile:

(imported comment written by JamesN91)

Thanks.

So in my custom group I created…

  1. Custom group \ Action Tab \ New Action

  2. Custome group \ Analyses Tab \ New Analysis

The new analyses did not produce the error I was having before.

The new analyses has ran but not added the size and time stamp to the “Docs.txt” created by the #1 action.

How does Bigfix know the Action Parameter “outputfile” is the same in both the new Action and new Analysis? They seem like unlinked independent defined variables. Are variables defined and retained within the custom group to be shared with the different actions or are the variables purged after each script has completed?

Should I have created a single fixlet using the Fixlets tab in my custom group instead of a individual action and individual analysis?

(imported comment written by NoahSalzman)

Haha… oops. Yeah, “parameter outputfile” is ActionScript. If you are going to have the Relevance be an analysis you have to hard code the path into the Analysis.

(imported comment written by BenKus)

Sorry guys… I only half answered this earlier in a confusing way… Rather than modify the property, you can just re-write the file in the action, to do this, you need to add a small part to the action I sent earlier…

// get the list of the files and their paths
parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt"
waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.MP3 >”{parameter “outputfile”}"

// go through the list in relevance to remove docs and settings and look up size/dates
appendfile {concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " & (size of file(it) as string) & " – " & it ) else nothings) of lines whose (it as lowercase does not contain “documents and settings”) of file (parameter “outputfile”)}

// replace the output file with the new file
delete "{parameter “outputfile”}"
move __appendfile “{parameter “outputfile”}”

I made the change in the post above too to avoid confusion… Note that I didn’t test this so let me know if I messed something up.

Ben

(imported comment written by JamesN91)

I need clearifacation on how to impliment this within BF.

Computer Groups \ My customer computer group \ ???

What tab?

Does all this code go into a new Fixlet

-ie

\Tab Fixlet\create new fixlet

Actions tab within new fixlet - add the following

// get the list of the files and their paths

parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\searchresults_MP3.txt”

waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.MP3 >"{parameter “outputfile”}"

Goto Relevance tab within new fixlet - add the following

// go through the list in relevance to remove docs and settings and look up size/dates

appendfile {concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " & (size of file(it) as string) & " – " & it ) else nothings) of lines whose (it as lowercase does not contain “documents and settings”) of file (parameter “outputfile”)}

// replace the output file with the new file

delete “{parameter “outputfile”}”

move __appendfile “{parameter “outputfile”}”

If the above is correct, how do I add limiting relevance statements for winxp in the relance tab?

If the above is incorrect, how do I create the actions?

I’m on the learning curve. Again I apologize for these basic questions.

###EDIT###

I created a single new Action within the custom group. I applied all code within the action script area.

The file was successfully created and date/size stamps were successfully added!

I will write a new Analyses to pull that txt file into big fix web.

Thank you for the help!

(imported comment written by JamesN91)

Almost there…

// get the list of the files and their paths

parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\doc_inv.txt”

waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:*.txt, *.doc, *.docx, *.docm, *.dotm, *.xls, *.xlsx, *.xlsm, *.xlsb, *.xlam, *.pptx, *.pptx, *.potx, *.potm, *.ppam, *.ppsx, *.ppsm, *.accdb, *.accde, *.accdt, *.accdr, *.mdb, *.ppt, *.pdf, *.zip >"{parameter “outputfile”}"

// go through the list in relevance to remove docs and settings and look up size/dates

appendfile {concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " & (size of file(it) as string) & " – " & it ) else nothings) of lines whose (it as lowercase does not contain “documents and settings”) of file (parameter “outputfile”)}

// replace the output file with the new file

delete “{parameter “outputfile”}”

move __appendfile “{parameter “outputfile”}”

2 issues…

  1. The “doc_inv.txt” only contains txt files. No other docx, pdf, etc. I have a “findme.rtf” that was not in the Docs_inv.txt. Worst case I could probally do multiple “Dir” searches and append to the Docs_inv.txt, but I would assume 1 command would do it all. After testing at the local dos prompt it almost seems to be a DIR issue.

  2. The second relevance statement does not parse out “Document and Settings” folder.

-ie

Tue, 15 Dec 2009 11:34:28 -0600 – 3213736 – c:\Documents and Settings\Administrator\Local Settings\Temp\XXXXX.txt

EDIT

Attempting a FOR loop…

FOR /d %n in (c:*) DO @IF “%n”==“c:\Documents and Settings” ("") ELSE DIR /s /b /TA c:\ *.doc, *.docx, *.docm, *.dotm, *.xls, *.xlsx, *.xlsm, *.xlsb, *.xlam, *.pptx, *.pptx, *.potx, *.potm, *.ppam, *.ppsx, *.ppsm, *.accdb, *.accde, *.accdt, *.accdr, *.mdb, *.ppt, *.pdf, *.zip >

(imported comment written by NoahSalzman)

This

dir

syntax is wrong:

dir /s /b c:*.txt, *.doc, *.docx

This is the correct syntax:

dir /s /b c:.txt c:.doc c:*.docx

(imported comment written by JamesN91)

// get the list of the files and their paths

parameter “outputfile” = “{pathname of parent folder of regapp “besclient.exe”}\doc_inv.txt”

waithidden {pathname of system folder}\cmd.exe /C dir /s /b c:.txt, c:.doc, c:.docx, c:.docm, c:*.dotm,

c:.xls, c:.xlsx, c:.xlsm, c:.xlsb, c:.xlam, c:.pptx, c:.pptx, c:.potx, c:.potm, c:.ppam, c:*.ppsx,

c:.ppsm, c:.accdb, c:.accde, c:.accdt, c:.accdr, c:.mdb, c:.ppt, c:.pdf, c:.zip, c:.rtf

“{parameter “outputfile”}”

// go through the list in relevance to remove docs and settings and look up size/dates

appendfile {concatenation “%0d%0a” of (if (exists (file (it))) then (modification time of file(it) as string & " – " &

(size of file(it) as string) & " – " & it ) else nothings) of lines whose (it does not contain "documents

and settings") of file (parameter “outputfile”)}

// replace the output file with the new file

delete “{parameter “outputfile”}”

move __appendfile “{parameter “outputfile”}”

This works! The only remaining issue is I still see files from Doc and settings

(imported comment written by NoahSalzman)

There are a number of ways to filter out the items in “Documents and Settings”:

  1. have your DOS command line filter them out

  2. process the outputfile using a second DOS command

  3. filter them out in the Relevance command

Here is the syntax for approach #1 (using a simplified example):

dir /s /b c:.txt c:.doc c:*.docx | find /v “Documents and Settings” > outputfile

You pipe the output from

dir

through the

find

command before you redirect the output to the outputfile. The

find

command uses the /v switch to omit lines containing “Documents and Settings”.

(imported comment written by BenKus)

In my example, you see that it has a part:

… whose (it does not contain “documents and settings”) of file …

But there is a small error here and it should be:

… whose (it as lowercase does not contain “documents and settings”) of file …

This should filter out the files and I prefer this method to Noah’s, but both should work…

Ben