Retain 7 most recent files, delete all others

How can I have a workflow delete all files within a folder, except the 7 files which were created most recently?
Thanks,
b.

This isn't easily done with the creation date, but with the modification date, try using the following AppleScript action:
tell application "Finder"
set the_path to quoted form of POSIX path of (folder of window 1 as alias)
set the_string to (do shell script ("ls -t " & the_path))
set delete_items to paragraphs 8 thru -1 of the_string
repeat with this_item in delete_items
delete item this_item of window 1
end repeat
end tell
This script operates on the frontmost Finder window.
(25045)

Similar Messages

  • I have Lion on my laptop and I want to back up my calendar TO my iphone. Not the reverse. iCloud only goes from iphone to iCloud to mac not the other way. Also, why doesn't "sync" mean update most recent changes across all devices?

    I have Lion on my laptop and I want to back up my calendar TO my iphone. Not the reverse. iCloud only goes from iphone to iCloud to mac not the other way. Also, why doesn't "sync" mean update most recent changes across all devices? I thought that was the point of iCloud. Any suggestions since iCloud doesn't seem to work?

    It's a work computer so I wanted to save them to my iTunes so I can access from another computer.  Should I go to a home computer and just Import for best results?  If so how do I do this?  Also, why would I be synched with another library and how do I find out what this is?  Very new/green user here

  • Email Most Recent File From Directory

    I am using C# to open a Spreadsheet, change 3 things in the spreadsheet, then save the spreadsheet in a directory, then open the directory.  I was trying to use FileSystemWatcher to capture the most recent file in the directory, but it seems that the
    Watch() event is being triggered before my syntax is able to make the changes and save.
    Is their a better method for this or do I just need to add in a Thread.Sleep() event so that the Watch() event triggers after the save is complete?

    Hi Indigo,
    >>I was trying to use FileSystemWatcher to capture the most recent file in the directory,
    but it seems that the Watch() event is being triggered before my syntax is able to make the changes and save.
    I have tested your code on my side, I supposed that you can add one button, when you
    change and save xls file successfully, try to trigger Watch() event by manual.
    I changed a little code with yours.
    Watch for changes in LastAccess and LastWrite times, and  the renaming of files or directories.
    Add all event handlers.
    Use messageBox to show something instead
    Here is my test reslut:
     Do I miss something? If so, please feel free to post here.
    public partial class Form1 : Form
    public Form1()
    InitializeComponent();
    filewatcher();
    private void filewatcher()
    using (Process pRun = new Process())
    pRun.StartInfo.FileName = "D:\\Test\\test.xlsx";
    pRun.StartInfo.UseShellExecute = true;
    pRun.Start();
    string openPath = "D:\\Test\\";
    Process pRC = new Process();
    pRC.StartInfo.FileName = openPath;
    pRC.Start();
    private void Watch()
    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.Path = "D:\\Test";
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
    | NotifyFilters.FileName | NotifyFilters.DirectoryName;
    watcher.Filter = "*.xlsx";
    // Add event handlers.
    watcher.Changed += new FileSystemEventHandler(OnChanged);
    watcher.Created += new FileSystemEventHandler(OnChanged);
    watcher.Deleted += new FileSystemEventHandler(OnChanged);
    watcher.EnableRaisingEvents = true;
    private void OnChanged(object source, FileSystemEventArgs e)
    WatcherChangeTypes changeTypes = e.ChangeType;
    String filename = e.Name.ToString();
    MessageBox.Show("Hello");
    private void button1_Click(object sender, EventArgs e)
    Watch();
    MessageBox.Show("DOne");
    //private void sendMail(string filename)
    // using (MailMessage mail = new MailMessage())
    // mail.From = new MailAddress("");
    // mail.To.Add("");
    // string fileDirectory = path;
    // string fileFullPath = Path.Combine(filesDirectory, filename);
    // if (!File.Exists(fileFullPath))
    // return;
    // using (var xlsx1 = new Attachment(fileFullPath))
    // mail.Subject = "Test";
    // mail.Attachments.Add(xlsx1);
    // SmtpClient client = new SmtpClient("SMTP.MAIL.COM");
    // client.Send(mail);
    Best Regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Cannot see most recent files when attaching

    I've had this problem for a while. Currently using OS X Mavericks, 10.9.4 (latest version) and Mail 7.3 (also latest build).  Saved a file to Documents, then opened Mail and attempted to attach it. Finder window opens, but my most recent files viewed are "last 7 days," with "today" being completely missing. I can open the Finder independently, the files show, I can open the files, send the file as an attachment from the Finder itself. But for quite some time, I don't see my most recent files (like today's files) in Finder when first opening Mail and attempting to attach something from a new message or message reply. Very frustrating.
    Anyone know what's going on here? I've experienced this before, but this is the first I realized that it seems as if it only happens when I am searching for a file to attach, and not when I open the Finder directly. I know there are workarounds, but I would just like to be able to do this simple thing, and for the life of me, I cannot do it. Not sure how long this has been going on, but I think it was happening in Mavericks all along, I just didn't connect the dots.
    Thanks.

    I can't duplicate the issue. What type of file is it? Is it saved locally, in the cloud, external drive?

  • Finding most recent file in a directory

    Hi,
    Is there a simple and easy way in labview to write a program that goes
    into a directory and looks for the most recent file. I can think of one
    way where I use the list directory vi to obtain an array of the file
    names in the directory and then use the file/directory info vi to
    obtain a time stamp for each file in the directory and afterwards sort
    all the time stamps. I'm not sure if this is the simplest way to do
    this, and wanted to ask if anyone on the discussion forums knows of any.
    Thank you

    unclebump wrote:
    Try here. http://zone.ni.com/devzone/cda/epd/p/id/3175
    This example is not that great and a few tweaks can greatly improve it!
    Building the path with string operations inside the loop automatically breaks this VI on anything but windows. There is a reason we have the "build path" function! It should always be used. The "string to path" and "path to string" should only be used for OS specific tasks.
    You probably want to skip files that are actually links. Newer versions of "File/Directory info" tell you if the path points to a link instead of a file with a boolean output.
    WIy do we need to keep an array of all files and maintain the corret index in a shift register. It seems more intuitive and less wasteful to just keep the newest file path in the shift register and not worry about the index.
    The image below shows a quick attempt at improving the example. Modify as needed.
    Message Edited by altenbach on 04-12-2007 02:45 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    find_newest_real_file.png ‏9 KB

  • When I sort by date added in Column View in Finder, how can I make the most recent files appear at the top of the list?(Mavericks)

    In 10.8, when I sorted Finder by date added or date created in column view, the most recent files would appear at the top of the list. Currently, this happens as it should in every single view mode EXCEPT column view (which is pretty much the only view I ever use). Currently, I have a folder with over 2000 files in it that date back to 2011, so now I have to scroll for like ten minutes just te get to files that were most recently added. Who in their right mind would want to sort by last modified with the oldest result listed FIRST? Ridiculous. I can't figure this out. Any help?

    Thanks for the reply leroydouglas! Unfurtunately this doesn't cause the column to be ordered correctly either. After selecting this option, the files seem to be ordered by label, and the most recently added file is somewhere in the middle of the list. I'd like it to be at the top, and have other files/folders descend in retrochronological order by their add date.
    Any other input from the community would be greatly appreciated, even if it's just confirming that this is/is not expected behavior. I'd be super bummed to find out that this IS expected behavior, as it's really counterintuitive and extremely inconvenient.
    Thanks again!

  • Let Photoshop automatically load the most recent file

    I have in the task bar icons for the PostScript editor PSAlter and for Photoshop.
    The workflow is always: Edit in PSAlter and interpret in Photoshop.
    Clicking in the task bar on the Photoshop icon should open Photoshop, load
    the most recent file (which is meanwhile modified), confirm last settings by OK
    and start the execution.
    Is it possible to automate this sequence – by just one click on the icon?
    Best regards --Gernot Hoffmann

    I doubt that would work out well.
    One could possibly link a Script to Photoshop being "brought to the foreground" with Script Events Manager but that might not always be the intended process when switching to Photoshop.
    How exactly is the "most recent file" identifiable?
    Do you change the settings often or could they stay fixed?
    Maybe you should also ask over at
    Photoshop Scripting

  • Not Showing Most Recent Files

    I've got a strange one. I've been able to network my imac to a dell laptop and they can see each other's shared directories. Tried to access an Excel file from the laptop and it didn't show the most recent file, but one that was nearly three weeks old. Is the imac caching the files anywhere? I didn't see any windows settings. Still getting used to the Mac world and didn't see any ability to refresh. Any ideas would be appreciated. Thanks in advance.

    Any pattern? Are they the most recently created or modified? Anything in common about how they are named, or in the +dot plus three+ extensions? Are you still seeing the older version of files on the Mac compared to directly in Windows.
    I've not used Windows 7 so I'm not familiar with any sharing filters that are possible. If you are still seeing older versions of files, and the ones you don't see on the Mac happen to be the most recently added to the folder, it still feels to me like you are actually connecting to a different sharepoint than what you believe... maybe one that is in an backup archive or something.
    Sorry I can't be any more helpful. It's a bit mysterious.

  • How can I modify Finder to actually find my most recent files?

    The more I use Finder the more I realize it's pretty crappy. The "recent files" folder never actually shows any files. And when I create my own recent files saved search, it's hit or miss as to whether it actually shows my recent files. All I'm trying to do is have an easy way to find files I've just modified or created, which should be really simple! Please help.

    Finder > View > Arrange By > Date Modified
    Shortcut is control-command-5

  • I want to save one cookie when exiting FF. I want to delete all other cookies.

    I want to save one cookie when exiting FF. I want to delete all other cookies. I have researched all related questions and answers but fail to see an answer to my question. Can "delete all cookies when exiting FF" have an exception?

    Here's some info that may be helpful.
    Installing Snow Leopard: What you need to know
    http://www.macworld.com/article/1142454/install_snow_leopard.html.
    You should get a Firewire connected hard drive and backup your MB's HD to it. That way, if something goes wrong during the installation, you can recover your current sytem, apps and files. After the SL install, you can use the external HD for frequent backups.
     Cheers, Tom

  • Most recent update changed all font sizes. What is best method to change back to to preexisting Fonts

    The most recent update changed all font sizes (smaller). What is the best method to enlarge?

    yeah, that's what I ended up doing late last night because the white font against pale gray background was driving me nuts. I hadnt changed anything. been using the same theme for about 4 months but then all of a sudden, like I said, the font color mysteriously changed.
    anyway, thanks for your help.

  • Recently I deleted all of my purchase history. HELP !

    Recently I deleted all of my purchase history. I realize that was a big mistake . It's asking me to pay for apps that I already bought . HELP !

    If you go onto your computer you can hide them n the iTunes Store. Now when I look at my apps (that I had previously bought) its says" buy now ?"

  • When I try to print sth I can´t choose my printer. Adobe Reader only shows a printer I used years ago.I aleady deleted and reinstalled the Reader and deleted all other printers from the computer.How can I add a new printer to Adobe Reader?Thanks for help!

    When I try to print sth I can´t choose my printer. Adobe Reader only shows a printer I used years ago.I aleady deleted and reinstalled the Reader and deleted all other printers from the computer.How can I add a new printer to Adobe Reader?Thanks for help!

    Hi,
    I would suggest you to uninstall Adobe Reader using the cleaner tool and then re-install the latest version.
    Adobe Cleaner Tool:- Download Adobe Reader and Acrobat Cleaner Tool - Adobe Labs.
    Latest version of Adobe Reader:- http://get.adobe.com/reader/
    If you still experience the same issue, please share the following information:-
    - Screenshot of Adobe Reader showing printer options
    - Screenshot of Microsoft Word showing printer options
    - Screenshot of control panel- Control Panel\All Control Panel Items\Devices and Printers
    Regards,
    Nakul 

  • IMac 500GB HDD occupied by 499.25 "other" files while all other types of files show "0 KB", what gives?

    iMac 500GB HDD occupied by 499.25 GB "other" files while all other types of files show "0 KB", what gives?
    I've tried cleaning up the HDD from HD tool twice and pressed command-option-P-R while restarting the Mac afterwards. The avaliable HDD space "improved" from 1.3 MB to 121 MB after the first restart and descresed down to 119MB after the second restart. I have kept very little AV files as well as doucment files. My application programs are just several GB. Is this a system problem. Do I have to reinstall the system?
    Much appreciate any advice!!
    BTW Apple customer service is on HOILDAY these two days from where I'm staying...

    You may find this Discussioon of interest and value...
    https://discussions.apple.com/message/18595469#18595469
    From the " More Like This " on the right.

  • "Adobe Premiere Pro 6 Quit Unexpectedly" - after deleting Cache files.  All other Adobe programs working.

    I went in and deleted Cached files after repeatedly getting the 'scratch disks are full' message.  I have done this before and have had no issues.  However, this time it comes up with a crash message whenever I open Premiere Pro 6.  All other Adobe programs are working fine.
    Does anyone know what could be wrong?  Have I accidentally deleted something crucial?  How can I fix this?

    If you have a 64bit Windows adding more ram will allow Windows to use that ram, and provide more to CS4
    Otherwise... here are some links I've saved that discuss crashes... may, or may NOT, help in your case... but free to read
    Firewall = Crash http://kb2.adobe.com/cps/857/cpsid_85711.html
    Win7 64bit Crashing and "a" fix http://forums.adobe.com/thread/580435
    Photo Scaling for Video http://forums.adobe.com/thread/450798
    -Too Large May = Crash http://forums.adobe.com/thread/879967
    -And another crash report http://forums.adobe.com/thread/973935
    Partition = Crash http://forums.adobe.com/thread/957286

Maybe you are looking for