![]() |
| |||||||
Automation Anywhere Post messages and questions related to Automation Software here. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| |||
|
Can a kind soul have mercy on a still-learning AA User? ![]() I can't seem to make a fairly basic task in AA work for me. I'm trying to delete certain files from a folder on my computer if the file name matches one in a list variable containing several file names. I'm sure it's just something simple that I'm missing, but I've attached relevant files here. To get to the most basic elements of this task, I created a test list variable with only one file name in it. Then I put a file with THAT name (ahead.ogg) into a folder on my computer. I can't even get my script to delete that one file .Any guidance appreciated! I've spent about 10 hours trying everything I can to make this work, to no avail. Thanks! Ken |
| |||
|
Hello, The variable name in text file and the one used in if condition are different hence the task is not working as expected. Attached is updated text file. Also, you can use 'Include' operator instead of 'Equal to' in If condition like this, Start Loop " Each File in D:\PIGTones\aa Delete Test" If $FileName$ Includes $DeleteTestAug09$ Then Delete Files "D:PIGTones\aa Delete test\$FileName$.$Extension$" End If End Loop Hope that helps. |
| |||
|
Thanks for the quick reply. I changed the text file to reflect the same variable name as in the If condition. I also adjusted the directory name spelling in the "Delete Files" instruction (had one letter lower-case). But that still did not do the trick. Here is what that test looked like: Start Loop " Each File in D:\PIGTones\aa Delete Test" If $FileName$ Equal To $DeleteTestAug09$ Then Delete Files "D:PIGTones\aa Delete Test\$FileName$.$Extension$" End If End Loop The text file has only this: DeleteTestAug09=ahead.ogg I then tried it with the "Includes" instead of the "Equals," and still no joy. Both tasks are attached. Is there still something wrong that I'm just not seeing? Thanks again! Ken |
| |||
|
Doh! I just made it work but I'm still not certain why it didn't work with the corrections you suggested .In my text file, I put the filename and extension like so: "DeleteTestAug09=ahead.ogg." I removed the extension from the reference to the file in the text file to read "DeleteTestAug09=ahead" and voila! BTW, it worked with both the "Equal to" and the "Includes" versions of the task. The only thing I can think of is that the IF condition states "If $FileName" Equal To..." and not If $Filename$.$Extension$ Equal To..." But I couldn't figure out how to enter both variables (Filename and Extension) into the If condition edit screen. Is there a way to do that? Either way, the immediate problem is solved!! Thanks for your help. Ken |
| |||
|
Hello, Yes, the system variable $Filename$ contains the file name only and not the extension. If you wish to check for both the file name and extension then you can try something like this, Start Loop " Each File in D:\PIGTones\aa Delete Test" If $Extension$ Equal To "ogg" Then If $FileName$ Equal To $DeleteTestAug09$ Then Delete Files "D:PIGTones\aa Delete test\$FileName$.$Extension$" End If End If End Loop Hope that helps. |
| |||
Grr. Another problem (sorry!)My goal is to delete 153 files from a set of 199 that I know will be in a directory. I thought I could create a list variable containing the 153 filenames I needed to delete. But I think I'm applying the If $Filename$ condition wrong. Here's what is happening in my tests as I build toward this: If my text file contains, say 5 of the filenames to be deleted, and the folder contains exactly those 5 or more, it works fine. However, if the first file in the folder does not match the first file in the text file, nothing gets deleted at all. There's a logic error here that I can't suss. Sorry to be dense. Am I missing something obvious...again? Example: Using the task attached, and placing the files "500.ogg, 600.ogg, and 700.ogg into the test folder, nothing gets deleted using the text file that says only "DeleteTestAug09=600,700." However, if I remove "500.ogg" from the test folder (leaving 600.ogg and 700.ogg only), and run the task again, both files get deleted. Hopefully I described this clearly. Thanks! Ken |
| |||
|
Hello, You need to create list variable, DeleteTestAug09 and use Loop for list variable inside 'Loop for each file in a folder'. Text format of task would be something like this, Start Loop " Each File in D:\PIGTones\aa Delete Test" Start Loop " List Variable DeleteTestAug09" If $FileName$ Includes $DeleteTestAug09$ Then If File Exists("D:\PIGTones\aa Delete Test\$FileName$.$Extension$") Then Delete Files "D:\PIGTones\aa Delete Test\$FileName$.$Extension$" End If End If End Loop End Loop We have attached sample task for your reference. Please copy it under location, 'C:\...\My Documents\Automation Anywhere\Automation Anywhere\My Tasks' folder. Note: Please ensure $DeleteTestAug09$ is List variable. |
![]() |
| Thread Tools | |
| Display Modes | |
| |