Search and delete a file from User Profiles

I am looking a relevancy and action script to search a particular file from different locations and delete.

In my case I am looking “java.exe” from user’s local profiles and delete it.

exists file “Java.exe” of folders “Bin” of folders of folder “C:\Users”

one of the eample is below.

C:\Users\test1\Documents\ij150-win-jre6\ImageJ\jre\bin\java.exe

My action script will be

delete __appendfile
delete __del.bat
appendfile {("del " & pathname of it & “%0d%0a”) of files “java.exe” of folders “bin” of folders of folder “C:\Users”}
copy __appendfile __del.bat
waithidden __del.bat
delete __appendfile
delete __del.bat

the relevancy is coming as false unless I put full file path. the file is at multiple locations and I want to search in all profiles.

???

The reason that the relevance is returning false is that it is written to search for a specific path for a variable list of users, rather than recursively across all folders under a given user’s profile. For instance, it would find the file in the following locations:

C:\users\test1\bin\java.exe
C:\users\testabc\bin\java.exe

While it is possible to perform a recursive search using relevance (see the descendant of <folder> inspector), I would not recommend doing so in a Fixlet’s (or action’s) applicability relevance as it is expensive, and will affect Client responsiveness.

One approach might be to run a ‘Scan’ Fixlet that will periodically output identified java binaries to a file which can then be referenced by a ‘Delete’ Fixlet.

If the folder locations (\Documents\ij150-win-jre6\ImageJ\jre\bin) are the same across all the users should be able to extend the “bin” name for the full folder path. If not the usage of the decendants of folder option listed by Aram might be your best practical option

appendfile {("del " & pathname of it & “%0d%0a”) of files “java.exe” of folders “\Documents\ij150-win-jre6\ImageJ\jre\bin\” of folders of folder “C:\Users”}

It is not the same accross all users. All I know is the first and last folder name.

Here is what my location, There are multiple dynamic folders between Users and Bin.

c:\users…\bin\Java.exe

I don’t recommend using this in a relevance (constant heavy relevance evaluation process to scan file structures) but below should work. If anything would create a task with a True relevance and run across any systems that you want to remove this file from. Another way would be to create an analysis and limit how often it is evaluated to maybe once a day/week and run an action separate based on the analysis returning “True”.

exists pathnames whose(it as string as lowercase contains “bin\java.exe”) of descendants of folder “c:\users”

1 Like

Thank you JBarter for the relevancy check. This is only onetime thing and will not run again. I also want to delete the file it finds in those folders.

Any action script thoughts?

this is the action script i am trying but it says "this expression contained a character which is not allowed

delete __appendfile
delete __del.bat
appendfile {("del " & pathname of it & “%0d%0a”) of files “bin\java.exe” of decendants of folder “C:\Users”}
copy __appendfile __del.bat
waithidden __del.bat
delete __appendfile
delete __del.bat

Smart quotes got you - the forum sometimes changes doublequotes to “smart quotes”, so you need to delete and retype all the doublequotes if you have copy/pasted from the forum.

The double quotes and if any of the directories have spaces it will also cause issues. This should solve both.

delete __appendfile
delete delete.bat
appendfile {("del " & “%22” & pathname whose(it as lowercase contains “bin\java.exe”) of it & “%22” & “%0d%0a”) of descendants of folder “c:\users”}
copy __appendfile delete.bat
waithidden delete.bat
delete __appendfile
delete delete.bat

And also I’ve noted that when copying from web pages the quotes " characters sometimes get replaced with another character that isn’t actually quotes due to ASCII character style issues. Just to make sure I typically paste the relevance between the relevance guards into the QNA debugger and it should highlight any of the characters that were replaced.

1 Like

I haven’t tested the actionscript, but this is an area where the preformatted text option helps when posting to the forum:

delete __appendfile
delete delete.bat
appendfile {("del " & "%22" & pathname whose(it as lowercase contains "bin\java.exe") of it & "%22" & "%0d%0a") of descendants of folder "c:\users"}
copy __appendfile delete.bat
waithidden delete.bat
delete __appendfile
delete delete.bat
1 Like

Thanks Aram didn’t know that option was there, I’ll use that in the future.

I will try it in the morning.

Thank you Aram and JBarter