Sunday, July 5, 2020

#1 2020-05-14 05:25:33 am

sebrady
Member
Registered: 2005-09-13
Posts: 36

delete certain files in a folder

here are some files in a folder and which ones need to be deleted, and which ones DO NOT get deleted.

05-15-20 OPEN EM.png -- DELETE
05-15-20 NDP EM.png -- DELETE
05-15-20 Bumper EM.png -- DELETE
05-15-20_TODAY EM.png -- DELETE
OPEN.png -- DO NOT DELETE
NEXTDAY.png -- DO NOT DELETE
BUMP1.png -- DO NOT DELETE
051520_TODAY.png -- DO NOT DELETE

here is my code, the delete command does NOT work.
Any ideas.

Applescript:

set the_weekday to weekday of (current date) as string


if the_weekday is "Friday" then
   set current_date to (current date) + (3 * days)
else
   if the_weekday is "Saturday" then
       set current_date to (current date) + (2 * days)
   else        
       set current_date to (current date) + (1 * days)
   end if
end if



--MONTH
set Monthof to month of current_date as integer -- 3
set Monthof2 to Monthof as string -- 3
set x to count Monthof2 -- 1
if x is 1 then
   set Monthof2 to "0" & Monthof2
end if


--DAY
set dayof to day of current_date -- 18
set dayof2 to dayof as string -- 3
set y to count dayof2 -- 1
if y is 1 then
   set dayof2 to "0" & dayof
end if



--YEAR
set yearof to year of current_date -- 2020
set yearof2 to yearof as string -- 3
set yearof3 to characters 3 thru 4 of yearof2


-- EXPORT NAME
set ExportFileName to Monthof2 & dayof2 & yearof3 & "_TODAY.png" -- 051520_TODAY.png



set the_promos to "OPEN.png, NEXTDAY.png, BUMP1.png, " & ExportFileName
set delete_these to ""

tell application "Finder"
   repeat with an_item in window 1
       set x to name of an_item
       if x is not in the_promos then
           set delete_these to delete_these & return & x
       end if
   end repeat
   delete every item in delete_these -- everything works but this command
end tell

Last edited by sebrady (2020-05-14 05:26:31 am)

Offline

 

#2 2020-05-14 05:37:58 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4534

Re: delete certain files in a folder

If I understand correctly you may try to edit the end of your script as :

Applescript:

set delete_these to {}

tell application "Finder"
   repeat with an_item in window 1
       set x to name of an_item
       if x is not in the_promos then
           set end of delete_these to x
       end if
   end repeat
   delete every item in delete_these -- everything works but this command
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 14 mai 2020 13:37:52

Offline

 

#3 2020-05-14 05:49:39 am

sebrady
Member
Registered: 2005-09-13
Posts: 36

Re: delete certain files in a folder

figured out a work around

Applescript:

tell application "Finder"
   try
       set the_EMs to select (every item in window 1 whose name contains "EM")
       delete the_EMs
       delay 0.5
   end try
   
   try
       set the_omfs to select (every item in window 1 whose name contains "omf")
       delete the_omfs
       delay 0.5
   end try
   
   try
       set the_v2cache to select (every item in window 1 whose name contains "v2cache")
       --delete the_v2cache
   end try
   
end tell

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)