Find & Delete file(s) with specific contents

written by sgreenwall91)

Trying to find and delete files with specific content. This is part of a task to upgrade Citrix client to a newer version of PNA agent. The problem being that When Citrix is uninstalled while desktop integration is turned on it can leave a bunch of orphaned .lnk files in multiple Windows profiles. Using the following relevance, I am able to find all the links that I want to delete but I’m having trouble turning the results into something I can use to delete the files:

pathnames of files whose (name of it contains “.lnk” and content of it contains “C:\Program Files\Citrix\ICA Client\pn.exe”) of folders of folders of folder “C:\Documents and Settings”

In order to delete the links I need to add quotes around the paths and/or create a batch using appendfile.

Problem 1) When trying to add the quotes, etc I’m consistently running into “Error: A singular expression is required.” when trying to concatenate the characters

Problem 2) When sending the results to __appendfile, the result is a continuous string without spaces or carriage returns

(imported comment written by brolly3391)

Hello sgreenwall,

You need to use %hex substitutions for your carriage return/line feed and for your quote characters.

“%0d%0a” is the same as pressing the enter key. “%22” is the same as a double quote.

Cheers,

Brolly

(imported comment written by sgreenwall91)

Thanks, this is the final solution. The key was to get it back to a singular expression by changing “pathnames” to “pathname”

delete __appendfile

delete ctxlinks.bat

appendfile {(“del “&”%22”&pathname of it&"%22"&" /q /f"&"%0d%0a") of files whose (name of it contains “.lnk” and content of it contains “C:\Program Files\Citrix\ICA Client\pn.exe”) of folders of folders of folder “C:\Documents and Settings” as string }

copy __appendfile ctxlinks.bat

wait ctxlinks.bat