![]() |
| |||||||
Automation Anywhere Post messages and questions related to Automation Software here. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| |||
|
How can I delete a s list of specific files from a folder? From a folder containing 116 wave files, I have to delete all but 47 of them. The files all have numbers in them, ex. "Voice_013, Voice_014, etc." I only need to keep, say, "Voice_002," "Voice_003," "Voice_047," "Voice_113," etc. (a total of 47 files). Is there a way to loop through the list of 116, deleting the ones that don't match the list, without having to do 47 separate "if/then" commands? I'm very new at this, and have figured out how to do the really common operations, but this one has me stumped. Thanks. Ken |
| |||
|
Hello, You can create a list variable that would read values from a text file. List all the file names that you do not wish to delete in that text file. Now, you need to insert nested loop. First insert an outer loop, Loop for each file in a folder. Inside this loop, loop for the list variable, can compare the file names and the delete the file that is not in the list. We have attached a sample task for your reference. To run this task, please follow below mentioned steps carefully, . Please copy .atmn file under location, 'C:\...\My Documents\Automation Anywhere\Automation Anywhere\My Tasks' folder. . Copy all .wav files under C:\. It would automatically create and store all the files in Temp folder. . Copy .txt file under C:\. Before running this task, please create variable, filelist through Variable Manager. To create a variable that read from text file, please follow below mentioned steps: 1. Go to Tools->Variable Manager in Automation Anywhere. 2. Click on 'Add New Variable'. 3. In 'Name' field, enter variable name i.e. filelist. 3. From Type dropdown select 'List'. 4. Select 'Read from text file' radio button or option. 5. In 'Value' field, specify the path of text file i.e c:\Test.txt. 6. Press 'Save' button. 7. Press 'Ok' button. Run the task. It would delete all other files from temp folder that are not listed in test.txt. Hope that helps. |
| |||
|
It created a very similar task to what you showed, because I realized I had forgotten to mention that though the "*_013" (the underscore and number) part of these files will be the same every time, the "voice" part (originally I said files called "voice_013") will be different every time. So the txt file for my filelist variable only contains the numbers I want to keep (013, 035, 036, 037, etc.). Then I "thought" I was check each file name to see if it "contained" one of the "keeper" numbers with: "If $FileName" Does Not Include $filelist$ Then" Not sure if that was right, because my Then task was: delete files "$CurrentDirectory$\$FileName$.$Extension$" does not result in any deleted files. I attached my file. Is it possible to see what did wrong? Thanks. Ken |
| |||
|
Here is a second attempt, since in the first one I forgot to go to the foler and loop through each file. But it still doesn't delete any files. Not sure what I'm doing wrong, but I still think it's how I'm doing the list. It only contains a portion of each file (the number part) that I want to keep. So I thought I had to compare each fileName with the list, and then delete that file if it didn't contain any of the numbers in the list. I'm gonna try again with some other ideas. Ken |
| |||
|
Hello Ken, We have amended your task and it works at our end. Please copy attached task under location, 'C:\...\My Documents\Automation Anywhere\Automation Anywhere\My Tasks' folder and run it. Please let us know how it goes. |
![]() |
| Thread Tools | |
| Display Modes | |
| |