Get newest file in a folder

Wow,
this must be so obvious...
How can i get the newest file in a folder.
I can get a list : list folder. But how to sort this list on creation date of the file.
Please help me on this one
thanks
Jitse

The Finder's scripting dictionary has a sort command:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #DAFFB6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
set someFolder to (choose folder)
tell application "Finder"
sort files of someFolder by creation date
if the result is {} then
log "no files"
else
get the first item of the result as alias
end if
end tell
</pre>

Similar Messages

  • How do you get copied files into a folder of our choice?

    OK so this may sound like a very basic question, but it has been driving me nuts ever since I bought an Apple Mac some 3 years ago and I find it hard to believe there isnt a solution.
    Objective: to copy or import files into a folder previously created by me within Apples 'Pictures' folder. E.g. "Holiday 2012".
    Problem: on every program I have used, inc iPhoto, iMovie, and just now, Preview, when I get ready to copy or import say my photo files from my iphone, or an SD card or a network drive, it never gives me the option to navigate to my folder! How mad is this?! Instead I get teh choice of just Apples plain old Documents or Pictures folders but NEVER get given any opportunity via the dialog box to navigate to my "Holiday 2012" folder. There just is not any obvious way to do it. So instead I get my hundreds of pictures listed directly under Pictures folder, to therefore added to all the other hundreds of pictures listed there. A terrible way to kep pictures.
    What I need: someone to tell me how to do this or if its not possible then to tell me that. It is a basic operation that I have been able to do on Windows PC's since they were built. Wht not on Mac? Maybe the solution is right in front of me... if it is then its not intuitive, thats all I can say!
    Can you help please?

    Hi. Ok.
    I have just tried the process again in Preview and in desperation this time clicked on 'Other' in the dialogue box when trying to Import. Low and behold I found the way to navigate to my own folders instead of being forced to use Apples standard Folders called Documents and Pictures.
    So problem solved.
    Its daft that you cant click on the first folder names listed like you can in Windows so you can then reveal the  subfolders. I guess its just another Apple-ism. Too bad it took me three years to find it but then I suppose I gave up early.

  • HELP!!! Can I get back files from a folder that has been copied over?

    I had a file in the trash with the same name as a file on my desktop. I accidentally started copying it from the trash to my desktop. It erased some of the files I had on my desktop in that folder that were very important, before I could stop it from copying. Is there any way to get the files back? They had been on my desktop for a few months. I'm thinking that maybe they are stored somewhere on the computer. I tried a search but came up with nothing. I usually back up to a external hard drive but I didn't this time and I'm paying for it now!

    When a file is erased, the space on the drive that the data occupies is not necessarily erased. It is just unallocated, so that other new data can use it. However, until that new data overwrites that same physical space on the drive, your old data may still be recoverable.
    To do this, you need to use a data recovery tool. There are tools that specialize in data recovery, such as
    http://www.prosofteng.com/products/data_rescue.php
    and other tools have a have multiple functions, including data recovery
    http://www.micromat.com/index.php?option=com_content&task=view&id=202&Itemid=107
    If you want to try recovering the data using such a tool, you should stop using the Mac (or use it as little as possible). Any use of the Mac will make it more likely that the space occupied by the old data will be overwritten. If that happens, the portion that is overwritten will not be recoverable.
    This is a good example of when Time Machine (part of Leopard and Snow Leopard) would be extremely helpful. It does backups to an external drive automatically, in the background, once per hour that the Mac is active. You just set it up and then forget about it. You can get any file back that you accidentally erase, even an older version of it.

  • How to get Latest file from a Folder

    Hi,
          I would like to access latest file in a folder based upon time stamp in the file properties. Can anybody help me in this regard.
    Regards,
    Visuman 

    Hey,
    I hope this solves your problem.
    If you have any questions, just ask them
    Greetz, Bart
    P.S. the solution is in the attachment
    Attachments:
    file.jpg ‏91 KB

  • Get invisble file of invisble folder?

    Hi
    I have an app that stores it's log files in a specific folder which is invisble, this is giving me a headache as id like to use folder actions to have the log copied and sent to another folder which is visible.
    Can I get some advise please a I cant figure out how to have applescript see the file when it's added to the invisible folder.
    cheers
    Budgie

    I'm a little confused by your post, too.
    There are no truly invisible folders, just ones that are not shown in a default folder view. You can always use the Finder's 'Go -> Go to Folder' menu option to open any folder on disk if you know its path.
    That said, the folder action shouldn't care whether the folder is hidden from view or not, and I'm not sure why you're using 'path to', either.
    For each folder action handler, the specific folder in question is passed in as one of the parameters. For example:
    on adding folder items to theFolder after receiving theseItems
    In this case, 'theFolder' refers to the folder the action is attached to. There's no need to do any other work to find it, and 'theseItems' is a list of the items just added to the folder.
    If you want a folder action that copies a file from a watched folder to another folder on disk it could be as simple as:
    on adding folder items to theFolder after receiving theseItems
    tell application "Finder"
    duplicate theseItems to folder "path:to:some:other:folder"
    end tell
    end adding folder items to
    and all the newly-added items will be copied to the specified folder (in this case "path:to:other:folder".
    Note, though, that this probably won't help with active log files. Folder actions will only fire when an item is added to or deleted from a folder. It won't detect if an existing file is updated in some way. Without knowing your goal it's hard to tell whether that's going to be a problem or not.

  • Is there any way to get the files from other computer ?

    Hai all,
    I have 2 computers connected. I know the IP address of other computer. Is there any way to get the files from other computer. (for e.g. I want to get the files from specific folder. In Java netwroking is it possible? (Any programs)
    regards,
    Namanc

    Bro Take it easy.
    Think you need to send a Image file named ("abc.gif")
    now develop a server using ServerSocket and connect it in local IP and any PORT
    For example i think ur server is connected in "localhost" and 9000 port.
    Now make ur server educated using some commands.
    For example:
    FileName: <File Name String>
    [Means new file is sending by connected client]
    FileSize: <File size long or int value>
    [ So that ur server can determind about the total length of sender file]
    DataModeOpen
    [Now your client will send its image data, this command means your client software is sending data]
    fjadlkfjaofaijojfwoeiurfodkjflsajlfksa
    l23j4lj23lkjlasjfoq23j4rokjelfkjasldkf
    2o3j4lk2j3ljslakdjf2l3j4 l23kjlk23k4j
    DataModeClose
    [Means file sending finished]
    Close
    [Means your client connection is closed]
    Now develop a client supporting this command.
    For example(Server):
    String getFileName=null;
    long getFileSize=0;
    public handleCommand(String getCmd) {
        if(getCmd.startsWith("FileName")) {
                String[] splitData=getCmd.split(":");
                this.getFileName=   splitData[1];
                outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("FileSize")) {
                String[] splitData=getCmd.split(":");
                this.getFileSize=Long.parseLong(splitData[1]);
                outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("DataModeOpen")) {
               //data mode open so receive data
              receiveData();
              outPutStream.writeBytes("+OK");
        } else if(getCmd.startsWith("DataModeClose")) {
              //close client socket
             getClientSocket.close();
    }For client:
    DataInputStream dataIn=null;
    BufferedOutputStream bout=null;
    public sendFile(bytes[] getBytes) {
            //if ok found then do other or show error message
        if(sendCmd("FileName:"+getFileName)) {
            if(sendCmd("FileSize:"+getFileSize)) {
                if(sendCmd("DataModeOpen")) {
                   bout.write(getBytes);
                } else {
                   showError(3);
            } else {
                   showError(2);
       } else {
            showError(1);
    }i think it will help u

  • (every document file of every folder in folder thePath) as alias list

    On Dec 9, 2006, at 1:03 AM, Bill Hernandez wrote:
    I use "set aList to get every file of every folder in startFolder" the references are to "document file path2file" instead of "alias to path2file", and I was not successful getting BBEdit to work with them without generating errors
    On Dec 9, 2006, at 9:25 AM, Jim Correia wrote:
    The open event requires a list of file references (aliases). This is true of all scriptable applications, not just BBEdit.
    Normally you can coerce Finder object references to aliases. In this case a bug in the Finder is getting in your way.
    set aList to get every file of every folder in startFolder
    This is returning invalid object references - ones not even the Finder can resolve at a later date.
    It seems to drop one level of hierarchy when building the object specifiers in response to that whose clause. You can avoid the Finder bug by using some alternate means of building up the file list.
    Jim
    Here's what I came up with, and it solved my problem...
    -- ---------+---------+---------+---------+---------+---------
    on script_title()
    Filename : getevery_file_ofevery.scpt (Script Debugger)
    Author : Bill Hernandez
    Version : 1.0.0
    Updated : Tuesday, January 02, 2007 ( 6:15 PM )
    end script_title
    -- ---------+---------+---------+---------+---------+---------
    on script_notes( )
    This is a work around to the alias list problem I encountered
    end script_notes
    -- ---------+---------+---------+---------+---------+---------
    tell application "Finder"
    activate
    set thePath to choose folder
    -- THIS DOES NOT GIVE THE CORRECT ANSWER --> instead of an alias list, it returns a document list
    set aSel to (((every document file in folder thePath) & (every document file of every folder in folder thePath)) as alias list)
    display dialog ("[2451] " & (get modification date of (item 1 of aSel)) as string)
    set f_info to info for (alias ((item 1 of aSel) as text))
    display dialog ("[2452] " & (get modification date of f_info) as string)
    -- THIS DOES THE TRICK, it returns an alias list
    set aSelection1 to (every document file in folder thePath) as alias list
    set aSelection2 to ((every document file of every folder in folder thePath)) as alias list
    set aSelection to (aSelection1 & aSelection2)
    display dialog ("[2453] " & (get modification date of (item 1 of aSelection)) as string)
    set f_info to info for (alias ((item 1 of aSelection) as text))
    display dialog ("[2454] " & (get modification date of f_info) as string)
    end tell
    -- ---------+---------+---------+---------+---------+---------

    Hi Bill,
    That's not really a bug. In this line:
    set aSel to (((every document file in folder thePath) & (every document file of every folder in folder thePath)) as alias list)
    two list are being concatenated which returns a list and 'as alias list' doesn't work on lists. You could do this:
    set aSel to (every document file in folder thePath as alias list) & (every document file of every folder in folder thePath as alias list)
    If there aren't anymore levels, then you can use 'entire contents':
    every document file of entire contents of folder thePath as alias list
    Note that if only one file is returned, then it will error because of automatic coercion, so it's better to do it your way if you don't know how many files there are. Then, you would use an error handler to trap the error. Here's what I've been using:
    try
    set aSel1 to (every document file in folder thePath as alias list)
    on error from o
    set aSel1 to o as list
    end try
    try
    set aSel2 to (every document file of every folder in folder thePath as alias list)
    on error from o
    set aSel2 to o as list
    end try
    set aSel to aSel1 & aSel2
    There is another way to coerce finder references to something usable in other applications that can't deal with Finder references. You can coerce Finder references to strings using text item delimiters.
    gl,

  • File Adapter - how to get the file count from a folder

    Hi All,
    I have a requirement that have to poll a directory when the file count is reached to number N (ex:number of files avilable in folder is 5) otherwise it should wait and not pick any of the files. Is it possible to get the file count from a folder using file adapter ?? otherwise please suggest me an approach to achieve this requirement.
    Thanks,
    JJ

    Hi Sarath,
    Thank you for your reply.
    Go with the list files operation of file adapter it will gives you the number of files in the specified folder as you given. . - this step is already done.
    When the number of files reaches your count startup your webservice that which can polls the files. . . - how can i acheive this?? Have to poll the directory and process the number files - please let me know, what could be added to the webservice which is being invoked after cheking file count from parent process.
    The reason for the above question is - we cannot use ReadFile operation in second webservice because it will be automatically triggered when the file is avilable. Also SyncRead operation supports reading one file in b/w bpel process. Kindly explain me the implementation steps.
    Thanks,
    JJ

  • How to get latest added file from a folder using apple script

    Hi..
    I am trying to get a latest added file from a folder..and for this i have below script
    tell application "Finder"
        set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
        set fileName to latestFile's name
    end tell
    By using this i am not able to get latest file because for some files the creation date is some older date so is there any way to get latest file based on "Date Added" column of a folder.

    If you don't mind using GUI Scripting (you must enable access for assistive devices in the Accessibility System Preference pane), the following script should give you a reference to the last item added to any folder. Admittedly not the most elegant solution, but it works, at least under OS X 10.8.2.
    set theFolder to choose folder
    tell application "Finder"
        activate
        set theFolderWindow to container window of theFolder
        set alreadyOpen to exists theFolderWindow
        tell theFolderWindow
            open
            set theInitialView to current view
            set current view to icon view
        end tell
    end tell
    tell application "System Events" to tell process "Finder"
        -- Arrange by None:
        set theInitialArrangement to name of menu item 1 of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "0" using {control down, command down}
        -- Sort by Date Added:
        set theInitialSortingOrder to name of menu item 1 of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "4" using {control down, option down, command down}
        -- Get the name of the last item:
        set theItemName to name of image 1 of UI element 1 of last scroll area of splitter group 1 of (window 1 whose subrole is "AXStandardWindow")
        -- Restore the initial settings:
        click menu item theInitialSortingOrder of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1
        click menu item theInitialArrangement of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1
    end tell
    tell application "Finder"
        set current view of theFolderWindow to theInitialView -- restore the initial view
        if not alreadyOpen then close theFolderWindow
        set theLastItem to item theItemName of theFolder
    end tell
    theLastItem
    Message was edited by: Pierre L.

  • Suddenly I cannot select just one file in a folder, all of them get selected at the same time.  Happens in Lightroom also when scrolling through the filmstrip. what did I do?

    My Mac Pro is acting wonky all of a sudden. This all began after someone in my family spilled water on the keyboard and tried to clean it up while still turned on. I bought a new keyboard but now I cannot select just one file in a folder, all get selected. Same thing happens in Lightroom 3 when editing in the filmstrip mode, I cannot just select one photo, they all get selected. Plus, after awhile I cannot type in small letters either, just capitals. If I restart it is ok for about 15 minutes then the problems start. I did a reinstall of the OS but it is still happening. I zapped the pram, fixed permissions, etc but no luck. I am on a 2x2.4 GHz Quad-Core Intel Xeon machine with 900 gigs unused. Any suggestions? 

    Try also resetting smc.
    Also check your keyboard preferences.  And just to possibly reset some keyboard related caches and prefs you might go through the "Change Keyboard Type..." (Keyboard tab in the Keyboard preferences).

  • I have one folder on an XSAN that one machine can not make changes to. Whenever I try to duplicate or copy a file in this folder I get 'The operation can't be completed because an unexpected error occurred (error code -50).'?

    I have one folder on an XSAN that one machine can not make changes to. Whenever I try to duplicate or copy a file in this folder I get 'The operation can’t be completed because an unexpected error occurred (error code -50).'
    The permissions are fine, and I have trashed the finder plist and reset the NVRAM.
    Anyone have a answer?
    Thanks

    Tips I received so far (thanks to A-Mac via Twitter http://www.a-mac.nl and Remco Kalf http://www.remcokalf.nl/)
    - make sure you have at least 10% of your harddisk in free space (I had only 5%).
    - do a PRAM-reset (http://support.apple.com/kb/ht1379)
    - perform a hardware test (http://support.apple.com/kb/HT1509)
    - make a complete backup (with for example Carbone Clone Copier, see http://www.bombich.com/)
    - after complete backup: use diskwarrior (boot from Diskwarrior DVD, first perform diagnostics, then perform "Rebuild" which rebuilds your file directory).
    So far I only cleared up some space on my HD, and already the problem occurs less.
    Still, I will go through the other tips too.
    (will post progress)

  • Need of a Webservice to get the name of the file in a Folder

    Hi All,
    I am in need of a Web service which should get the name of the file in a folder.
    Note :  Folder is created in the MOSS server.
    Thanks.

    Just to add, Mac in intergrated into AD and all I need is help in creating the script
    Thanks

  • Cant get list of files from a folder (even though the folder and files are created with the same app)

    Ok so each character rolled with my app gets saved as an html file in a folder i create on the sdcard called RpgApp
    the code to do this is 
    private async Task saveToHtmlCharacter(string name)
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    StorageFolder sdcard = (await externalDevices.GetFoldersAsync()).FirstOrDefault(); //Windows.Storage.ApplicationData.Current.LocalFolder;
    var dataFolder = await sdcard.CreateFolderAsync("RpgApp",
    CreationCollisionOption.OpenIfExists);
    var file = await dataFolder.CreateFileAsync(name+".html",
    CreationCollisionOption.ReplaceExisting);
    using (StreamWriter writer = new StreamWriter(await file.OpenStreamForWriteAsync()))
    writer.WriteLine("<html><head><title>Character File for " + z.charNameFirst + " " + z.charNameSecond + "</title></head><body>");
    //trimed for the post
    now this as i say works perfectly and i can confirm that the files show up in the "RpgApp"folder
    now the next step is to have the app read the names of each of those html files and create a seperate button for each one named for the filename and with the filename as content (later i will link them up to load the html file they are named for in a webbrowser
    panal)
    here is the code that *should* do that
    private async Task readFiles()
    z.test.Clear();
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
    IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
    //z.test.Add("dummy");
    foreach (StorageFile file in fileList)
    z.test.Add(file.Name);
    public async void buttonTest()
    await readFiles();
    CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    foreach (string name in z.test)
    Button button1 = new Button();
    button1.Height = 75;
    button1.Content = name;
    button1.Name = name;
    testStackPanal.Children.Add(button1);
    now i say should as what i get is an error of "A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll" (2 of them in fact one after another)
    more detailed error is at http://pastebin.com/3hBaZLQ9
    now i went through checking line after line to find the error and line that causes it is:
    StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
    in the readFiles method
    i checked to make sure the case is right etc and its spot on, that IS the folder name, and remember my app creates that folder and creates the files that are inside that folder (and only files my app creates are in that folder) so it should have access
    im 100% stuck its taken me all day to get the files to save and now i cant get them to list correctly
    I have tested the button creation function with fake list data and that worked fine, as i say the error is when i tell it to look at the folder it created
    all help most greatfully recieved

    this was actually solved for me on another forum thread 
    async Task<bool> continueToReadAllFiles(StorageFolder folder)
    if (folder == null)
    return false;
    if (folder.Name.Equals("RpgApp", StringComparison.CurrentCultureIgnoreCase))
    var files = await folder.GetFilesAsync();
    foreach (var file in files)
    test.Add(file.Name);
    return false;
    var folders = await folder.GetFoldersAsync();
    foreach (var child in folders)
    if (!await continueToReadAllFiles(child))
    return false;
    return true;
    public async void buttonTest()
    test.Clear();
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    var folders = await externalDevices.GetFoldersAsync();
    foreach (var folder in folders)
    if (!await continueToReadAllFiles(folder))
    break;
    //.... commented out
    ...now i say solved this is more a workaround...but it works.
    I would love to know why we cant just scan the RpgApp folder instead of having to scan the whole dc card and disregard all thats not in the RpgApp folder

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • Function module to get the file path in the system for TEMP folder

    Hi All,
    Is there any function module that I can use to get the file path in the system for TEMP folder.
    I mean, i am supposed to give only TEMP as the input for that function module and I need to get the path of that in the system as the output.
    I am unsing 4.0 version.
    Please advice.
    Regards
    Ramesh

    In Higher versions, we can use the below code:
    call method CL_GUI_FRONTEND_SERVICES=>ENVIRONMENT_GET_VARIABLE
        exporting
          VARIABLE   = 'TEMP'
        importing
          VALUE      = LV_TMP
        exceptions
          CNTL_ERROR = 1
          others     = 2.
      if SY-SUBRC <> 0.
        message id SY-MSGID type SY-MSGTY number SY-MSGNO
        with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
      call method CL_GUI_CFW=>FLUSH
        exceptions
          CNTL_SYSTEM_ERROR = 1
          CNTL_ERROR        = 2
          others            = 3.
      if SY-SUBRC <> 0.
    Error handling
      endif.
      concatenate lv_tmp '\' into folder_path.
    But need to know in the lower versions like 3.1h and 4.0,

Maybe you are looking for

  • TC can't join existing wireless network

    Hi, yesterday I played around with my TC and tried to extend my existing wirelss network. Therefore I changed the settings from "Connect to wireless network" to "Extend a wireless network". After I found out that this feature only works on only n-ena

  • MSIGE60 not using dedicated graphics?

    i everyone, I recently purchased a refurbished MSIGe60 laptop online equipped with a 2gb Nvidia Gtx660m and has the integrated intel HD 4000 as well. My laptop at the moment seems to be always using the Intel graphics, because I am getting terrible p

  • How do I get audio back on single clip that loses audio when imported into Premiere Pro CC?

    I've got one clip out of many that for some reason won't play any audio when imported into Premiere Pro.  I am new to Premiere Pro so am hoping it's something stupid I've done, but this is a problem with just a single clip exported the same way as al

  • Native ZFS for Linux

    Oboy. http://github.com/behlendorf/zfs

  • Insert timer in the AC

    Hi All, I would like to insert a timer in the AC file during some case study (not in quiz slide). Will anyone could help? Cheers, Katherine