Here is the scope of what I am trying to do:
Query the action for a file name. Example : Test123.txt and delete the file from any descendant location of the given root folder.
Here is my script. I am getting a relevance error stating that the expression contained a character which is not allowed. (I believe this has to do with embedding the parameter into the embedded relevance contained in the action script.
delete __appendfile
//Query user for file to Delete
action parameter query "DeleteFile" as lowercase with description "Enter your File to Delete from all of C:\Users"
appendfile {concatenation "%0d%0a" of ("del /q %22" & it & "%22") of pathnames of find files (parameter "DeleteFile" of action as lowercase string) whose (now - modification time of it > 0 * day) of (it; descendant folders of it) of folders ("c:\users";"c:\data")}
delete RemoveFiles.bat
move __appendfile RemoveFiles.bat
waithidden cmd /c RemoveFiles.bat
If I remove the parameter and replace it with a static file name, the action runs flawlessly. (See Below)
delete __appendfile
//action parameter query "DeleteFile" as lowercase with description "Enter your File to Delete from all of C:\Users"
appendfile {concatenation "%0d%0a" of ("del /q %22" & it & "%22") of pathnames of find files ("Test123.txt" as lowercase) whose (now - modification time of it > 0 * day) of (it; descendant folders of it) of folders ("c:\users";"c:\data")}
delete RemoveFiles.bat
move __appendfile RemoveFiles.bat
waithidden cmd /c RemoveFiles.bat
I don’t think you can use ‘as lowercase’ on the parameter query line. Try
action parameter query “DeleteFile” with description “Enter your File to Delete from all of C:\Users”
(I don’t think ‘find files’ is case-sensitive, and you’re already converting to lowercase where you use it, so lowercasing on the query shouldn’t matter anyway)
Do you get this error in the console when you try to save it, or do you get the error when the action runs on a particular client?
If you get this error when trying to save it in the console, then that usually means you have somehow copy and pasted a bad character into the console.
This is incorrect, and probably the source of the error. It should be as string as lowercase
The as lowercase that @JasonWalker mentions in the action parameter query is also incorrect.
This action is pretty heavy handed, could be slow, and could delete a lot of unintended things, so be careful.
Thanks for the insight JGstew,
This is going to be used to perform a very specific task so I am OK with the "heavy handedness"
I also intend to test extensively before going live.
I was able to get this working. It did not like being ran through the debugger, but once entered into an actual task, it runs as intended.
Here is the working code:
delete __appendfile
action parameter query “DeleteFile” with description “Enter your File to Delete from all of C:\Users”
appendfile {concatenation “%0d%0a” of (“del /q %22” & it & “%22”) of pathnames of find files (parameter “DeleteFile” of action) whose (now - modification time of it > 0 * day) of (it; descendant folders of it) of folders (“c:\data”;“c:\users”)}