Need script to read a list and compare it to the contents of a folder...

I need a script that will read all of the file names within a tab delimited list and then compare them to the files within a directory (named IMAGES) and delete the files of this IMAGES folder that are not included in the list.
Thanks in advance.

It won't work because of what you're comparing.
Consider if files_list does not contain (image_file as string) then.
Your script defines files_list as the contents of the specified file like:
"file1.jpg
file2.jpg
file3.png"
and image_file is a list of files which, when coerced to a string looks like:
"Cabezon:Users:cochino:Desktop:images:file1.jpgCabezon:Users:cochino:Desktop:ima ges:file2.jpgCabezon:Users:cochino:Desktop:images:file3.png".
There is no way files_list is going to be in image_file.
Instead you're going to have to iterate through one or other of the lists and find matches.
Since the list of files you want to keep is around 1,000 items long, and there are 6,000 files in the directory it would be quicker to iterate through the list of files to keep (a loop of 1000 iterations) than it would be to loop through the files to see which ones to delete (a loop of 6000 iterations).
Therefore your best bet is something like this (untested):
tell application "Finder"
--define the source directory
set sourceDir to folder "Cabezon:Users:cochino:Desktop:images:"
-- create a temp dir for the files to keep
set filesToKeepFolder to (make new folder at (path to temporary items) with properties {name:"TempImageDir"})
-- get the list of files to keep
set files_list to paragraphs of (read file "Cabezon:Users:cochino:Desktop:Workbook2.txt")
-- iterate through them
repeat with eachFile in files_list
try
-- move the file to the temp folder
move file (eachFile as text) of sourceDir to filesToKeepFolder
end try
end repeat
-- by the time you get here all the matched files
-- have been moved to the temp dir
-- so now you can throw away the rest of the files
delete every file of sourceDir
-- and copy the files you want back in
move every file of filesToKeepDir to sourceDir
-- and clean up
delete filesToKeepDir
end tell
The comments should give you some idea as to what it's doing, but in short it walks through the list of files looking for matching files in the specified directory. If it finds a match it moves that file to a temporary directory. At the end of the 1,000 iterations, what's left in the directory are the files that did not match the file read in at the beginning, so these files can be deleted.
Finally, to clean up, the files you want are copied back into the images directory and the temporary directory is deleted.

Similar Messages

  • There appear to be big problems with Mavericks Mail, particularly if it's used for Gmail. Have other users noticed that it slows to a crawl and can't reload the contents of a folder instantly....Is there a fix coming?

    There appear to be big problems with Mavericks Mail, particularly if it's used for Gmail. Have other users noticed that it slows to a crawl and can't reload the contents of a folder instantly....Is there a fix coming?

    There is a large thread relating to Gmail, but nothing that sounds like that.
    Nobody here knows what Apple is going to do.
    You might try removing the Gmail account and then add it back in.

  • Has anyone got a script to read a list of email addresses from a Mail message and put them into a group in Contacts?

    Has anyone got a script to read a list of email addresses from a Mail message header and put them into a group in Contacts?

    Now Tony, I know you can't hear my tone on a forum post but I was not complaining, simply stating facts . This change brought several people in my office to a grinding halt in a long established workflow that is really rather simple (and I thought was already assumed from the original post above ):
    1) Select a set of records in FileMaker Pro 12 and export only their e-mail addresses as a CSV file.
    2) Open that CSV file in Excel.
    3) Copy the column of e-mail address.
    4) paste into the appropriate recipient field in Mail.
    5) Send
    If I were to complain it would be about Apple's typically opaque approach to updates. There is no granular explanation of why changes were made or even "what" changes were made.
    Complaining is futile since Apple is Apple and is unlikely to change, but sometimes it is cathartic to "shout into the void" .
    I had thought about doing something with a formula in Excel and your suggestion was simple and helpful. Again, however, it is only a workaround for a long established helpful behavior that Apple has inexplicably broken/removed in Mavericks Mail.
    I, and the other posters here, would love to have the capability back rather than have to add previously unneeded steps to our workflows.
    Ultimately we may add scripting steps to the FileMaker side to export the address lists with commas inserted already if Apple ends up having permanently removed this feature.

  • My MacBook Pro will not open documents via Adobe Reader. Says I need to aspen Reader in Browzer and accept terms and contitions first. Went through this 3 times and got through to "Finish", closed browser and then retried. No luck. What's going on?? Have

    My MacBook Pro will not open documents via Adobe Reader. Says I need to aspen Reader in Browzer and accept terms and contitions first. Went through this 3 times and got through to "Finish", closed browser and then retried. No luck. What's going on?? Have no problem with same documents on iPhone and iPad

    After you finished installing did you launch Adobe Reader from your /Applications folder and accept EULA(End User License Agreement)?
    What is your Adobe Reader version?
    What browser are you using and browser version?
    Thank You.

  • Adobe reader XI crash and hangs when open the pdf file

    After update the adobe reader xi 11.0.10, the reader always crashes and hangs when open the pdf file. Please help me how to do.

    Ben Leung wrote:
    HThis situation is started after I clear the pop up advertisement.
    What kind of advertisement?  In Adobe Reader?  Can you post a screenshot of that: https://forums.adobe.com/thread/1070933
    Regarding the crash, can you try disabling Protected Mode through the registry: download, unzip, then run the registry script https://files.acrobat.com/a/preview/49eeb48b-07c5-4502-984c-8a25259914fa

  • HT1349 I have downloaded 4 films purchased on my Ipad to my laptop but can only play 1.  The other 3 do not have a screen symbol in the list and are called ie The Lion King - Extras.  How can I play the films?

    I have downloaded 4 films purchased on my Ipad to my laptop but can only play 1.  The other 3 do not have a screen symbol in the list and are called ie The Lion King - Extras.  How can I play the films?

    Hello Bagpus113
    Check out the article below to troubleshooting issues with the sound for music and for videos. One other thing you can try is to convert the songs to a different format
    iTunes and QuickTime for Windows: Audio does not play or plays incorrectly
    http://support.apple.com/kb/TS1362
    Troubleshooting iTunes for Windows Vista or Windows 7 video playback performance issues
    http://support.apple.com/kb/ts1718
    iTunes: How to convert a song to a different file format
    http://support.apple.com/kb/ht1550
    Regards,
    -Norm G.

  • Hi - I need to download an iPad update and when I do the file successfully downloads and then proceeds to "progressing" then times out - I think it is my firewall but I have turned off all firewalls

    Hi - I need to download an iPad update and when I do the file successfully downloads and then proceeds to "progressing" then times out - I think it is my firewall but I have turned off all firewalls

    If it scare y ou then take the machien back and ask the Apple Store to do this for you. What has probably filled your computer is large libraries such as music,  photos and movies. Apple explains how to move those libraries to an external HD. Please read:
    http://www.macworld.com/article/1153165/move.html
    http://support.apple.com/kb/PH2506
    http://support.apple.com/kb/ht1449
    http://support.apple.com/kb/PH2506

  • Need to get a mibile computer and i am considering the macbook pro 15". Is that a good idea?

    Need to get a mibile computer and i am considering the macbook pro 15". Is that a good idea?

    The 15" is the ideal size, the 17" is a bit larger and more comfortable.
    The 13" is a bit cramped, the 11" forget it.
    The 11 and 13" have the poor Intel HD 3000 integrated graphics (solely) which are not good at 3D gaming/video and tend to overheat as the CPU is also doing the graphics.
    The 2.0 Ghz 15" MacBook Pro has a slightly better video card that does average on most current 3D games.
    The 2.2Ghz MacBook Pro (and higher) does excellently on 3D games with the powerful 1GB radeon 6750M and "future proofs" your computer investment for 3, 5, 7 years or longer.
    It all depends upon your portability and use needs.
    If your not a 3D gamer and can afford to replace your machine in shorter time periods and all you need is a basic laptop, then one of the smaller thinner machines will do. In fact even a Windows PC laptop can do. There really isn't any advantage of going for a Mac laptop at the lower end excpet for status symbol appeal. Your going to be paying $1500 for a laptop that a $800 PC will do just as well.
    However if your needing more of a portable workhorse machine the 2.2 Ghz MacBook Pro or better is ideal, it can run jsut about all the operating systems out there well, bootcamp into Windows and everythng with it's strong hardware and decent sized screen.
    Also the 15" and up have the optional ANTI-GLARE screens which is great for classes and at work where you can't control the enviroment to reduce reflections.
    If your on the go a lot, you can get a iPad in addition to the 15" MacBook Pro, if you need a larger screen you can buy that and use the MBP as a desktop machine sort of.
    The smaller Mac machines don't drive a larger monitor very well, really you need a dedicated graphics card.

  • After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and conver

    After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and convert raw files. MacBook Pro with Snow Leopard. No such problem before this reinstallation.

    You should install Camera Raw 4.6.
    Visit this page and follow the instructions carefully:
    PC:    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4040
    Mac:  http://www.adobe.com/support/downloads/detail.jsp?ftpID=4039
    -Noel

  • How to synchronize if one servlet read a file and anothe servlet update the

    How to synchronize if one servlet read a file and anothe servlet update the file at a time?

    Create a class that holds the reference to the file and do the whole file manipulation just in that class. than synchronize the read and write methodes. A reference to this file handler class can be stored to the servlet context in one servlet and read out from the servlet context in the other servlet.

  • I am being forced to create 3 security question from your dropdown list and I can choose the questions but can't enter anything in the answer field??

    I am being forced to create 3 security question from your dropdown list and I can choose the questions but can't enter anything in the answer field??

    The problem is twenty three people leaving or twenty three thousand leaving has zero impact on a carrier with over 100 million customers. And they have the lowest churn rate. So if 10,000 or 20,000 or more churn out it means little to the carrier.
    If you have a real lawyer he/she will advise you that you have no case. The device was not lost or stolen by the carrier, you were not eligible for a new device, and like any business who employs large numbers of poorly trained personnel who make low wages what was told to you is not in writing. So a verbal exchange does not hold up.
    In fact in Verizon's customer agreement it has such a disclaimer against any verbal exchanges so if you have that agreement in writing, go get them.
    The posting on public forums and places like Face Book, Linkin, Google+ or a personal web site can open you up to a lawsuit for Dilution of Trade Name, and other offences. However if you have proof then go for it.
    Unfortunately that is how big business works today. A pity

  • Upgrading from 10.4.11 to 10.7. What are the steps and do I also need to pay for 10.5 and 10.6 along the way?

    Hi. I wannt to upgrade from 10.4.11 to 10.7.
    What are the steps and do I also need to pay for 10.5 and 10.6 along the way?
    According to the 10.7 lion page on 'store' it says that you need 10.6 to use it does this mean I'm going to have to do 3 upgrades?
    Thanks

    Why do yoy want Lion/10.7???
    Anyway, if your Mac meets the requirements you can skip 10.5.x, and even 10.6.x if you can afford to erase all your data.
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 4GB at least)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    It looks like they might still have it...
    http://store.apple.com/us/product/MC573Z/A?fnode=MTY1NDAzOA
    If it's a core Duo & not a Core2Duo, then it'll only run in 32 bit mode.
    Lion/101.7 System requirements
        •    x86-64 processor (Macs with an Intel Core 2 Duo, Intel Core i3, Intel Core i5, Intel Core i7, or Xeon processor.)
        •    At least 2GB of memory[14]
        •    Latest version of Mac OS X Snow Leopard (10.6.8), with the Mac App Store installed
        •    At least 4GB of disk space for downloading[14]
    Like Snow Leopard, Lion does not support PowerPC-based Macs (e.g., Power Macs, PowerBooks, iBooks, iMacs (G3-G5), eMacs).
    Lion also does not support 32-bit Intel Core Duo or Core Solo based Macs. Rosetta is no longer available in Lion, which means Lion no longer supports PowerPC applications.
    http://en.wikipedia.org/wiki/Mac_OS_X_Lion#System_requirements
    http://www.apple.com/macosx/how-to-buy/
    What applications are not compatible with Mac OS X 10.7 "Lion"?
    http://ow.ly/5Iz09
    http://roaringapps.com/apps:table

  • Script that takes 2 images and overlays one on the other

    I have a folder with 200 raw images in it. 100 of them might be called 1001-1001-1072 (Yellow).jpg and it's sister image would be 1001-1001-1072 (Yellow)_Overlay.jpg - making 200 images. The next image in the series might be 1001-1001-1073 (Red).jpg. It's really the last string of numbers that the script should look at.
    Basically each image will have a sister image that will be used in photoshop as an overlay layer (of a script defined percentage). Can one of you geniuses create a script for me that will do this to all the images in a folder?
    I'd like to use this inside of an action, if that means anything in the script parameters...
    Thanks in advance for trying -
    Ian

    Sorry, the correct layer interaction should be SCREEN on top of the other image, not Overlay.
    tnx

  • I want to cancel my ipod and its contents on one pc because i have a notebook and want to install the contents onto this notebook,i have burned all my library to disc to install on notebook

    i wish to move my ipod classic,s contents to another pc[notebook] so need to cancel current p.c,i have burned all the contents on to disc and i am waiting to transfer these to my notebook.i have tried to do this originally but was stopped due to me being registered on another p.c,how do i cancel current p.c registration and open new account on notebook

    You will lose your app data unless you backup to the new computer and then restore from backup will all the app in the iTunes library of the new computer.
    iKnowiPod wrote:
    Try this:
    1. Sync to your Windows XP desktop so you do not lose anything.
    2. Turn on Sharing.
    3. Import your iTunes data from the Windows XP to your Windows 8.1 through Sharing.
    4. Connect iPod to Windows 8.1 laptop, erase and re-sync.
    5. You lose nothing.
    6. Shazzam.

  • I have the latest version of free Quicktime, Itunes  and unable to view video on my PC all i get is a pink screen the audio is OK i have uninstalled and installed several times same problem, i have a Iphone 4 and unable to view the content.

    i have the latest version of free Quicktime, Itunes  and unable to view video on my PC all i get is a pink screen the audio is OK i have uninstalled and installed several times same problem, i have a Iphone 4 and unable to view the content.

    Open your QuickTime control panel (either via the Control panels, or by going "Edit > Preferences > QuickTime Preferences" in the Quicktime Player). In the Advanced tab, uncheck Enable Direct3D video acceleration:
    ... and click OK. Quit and restart the QuickTime Player prior to checking to see if the settings change has had any effect.

Maybe you are looking for

  • GPS Maps Language

    I am a user in Hong Kong, I would like to know if I can turn the map into english instead of showing the Chinese roads and streets? Thanks

  • How to directly wire in more than one machine

    Hello all, I am probably going to buy this router. Right now I have one machine right near the cable modem so it can be directly wired in. My laptop and Imac can hook up wirelessly. I see that there is one LAN port for a machine to be directly wired

  • Writing File and File Member to AS400 using Access Classes

    Hi! All, I am in a fix here and would sincerely appreciate any help I can get. I need to write a pogram that will allow me to write a file and many FileMembers to the File in the AS400. I have the following method which I thought would help me do it,

  • Can I run CS6 on Desktop and CS5 on Laptop at the same time?

    First off, let me start by saying I am a small business owner. I am at work between 10 to 16 hours per day, every day. I have very little time in my life that I am not sitting at my main desktop macintosh, unless I am sleeping. All of my my work file

  • Web Logic Query

    Hi, I am Piyush, I am stuck in calling different services from my proxy service.. I have two bussiness services and i want to call them from my Proxy Service, I have tried using Service Callout but there it is asking me some SOAP Request Body and SOA