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

Similar Messages

  • 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.

  • 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!

  • 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?

  • 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.

  • Find the most recent file

    greetings,
    I am developing a web site in which we need to extract the 1st paragraph of the most recent press release and post it as content in a separate page. The press releases are all in their own separate files that get dynamically included into a templates page.
    I am able to open the file, get the text, set it to a variable and post to the separate page without a problem. What I need to know is how to know which file to open and read.
    I can use the lastModified() method to compare one file agains another, which I suppose would work fine it it was only a handful of files I Was comparing, but this could potentially be a pretty large number of files.
    Can anyone think of a relatively efficient way to do this? Are there any array sorting methods that may help here?
    Thanks,
    -d

    If you're looking to sort your File array by lastModified() date, then use the Arrays.sort() method with the following header...
    Arrays.sort(Object[] a, Comparator c)
    You can easily define the Comparator to sort by the date (either ascending or descending) and voila, you can quickly and easily find the most recent.

  • 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

  • Automatically keep 2 most recent files?

    hi, i have a folder that i keep synced and that i access remotely.  however, i would like to find a way to always keep the most 2 recent added files in t hat folder... how could i do that? with automator? or applescript? im not too familiar with apple script. (not at all actually)
    im looking for something a bit like dropbox where that folder would be monitored all the time and as soon as it senses that a new file was just added, it would delete the oldest by keeping always the most recent 2....
    any ideas?
    thanks... (running most recent version of mountain lion)

    Hello, to get you started, Watched Folder...
    http://www.mactech.com/articles/mactech/Vol.20/20.07/FolderWatching/index.html
    http://hintsforums.macworld.com/archive/index.php/t-9652.html

  • 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)

  • Full restore from Time Machine - how do I get most recent files back???

    Hi all,
    I've had some major problems with my hard-disk today (Disk Utility complaining about all sorts of things and not being able to repair them) so I thought I'll just wipe my disk and restore from back-up.
    But: when I was asked to choose a backup the most recent one was from 7th November. It said that only full backups are shown (and incremental backups are not shown...). Well, since I had no choice anymore, I selected the most recent one and hoped I could get things back again later. But I'm now struggling to find a decent way of doing this:
    All the more recent versions are on the time machine disk - I can see the files in the different folders. But in Time Machine itself, I cannot select any of the back-ups from between 7th November and now - they are shown to exist, but they are greyed out.
    Is there any way to return to my most recent state other than restoring the whole thing one-by-one from dozens of different folders?
    Any help would be greatly appreciated
    Thanks in advance!
    Sebastian

    Sebastian Hoffmann wrote:
    But: when I was asked to choose a backup the most recent one was from 7th November. It said that only full backups are shown (and incremental backups are not shown...).
    No, incomplete backups are not shown, including backups that failed, were cancelled, or were made with System files excluded. Other than that, all TM backups are, in effect, full ones.
    All the more recent versions are on the time machine disk - I can see the files in the different folders. But in Time Machine itself, I cannot select any of the back-ups from between 7th November and now - they are shown to exist, but they are greyed out.
    Is there any way to return to my most recent state other than restoring the whole thing one-by-one from dozens of different folders?
    Could you have renamed your internal HD on or about November 7? That's one possible explanation for what you're seeing. If so, TM would treat it as a separate disk: there would have been two disks listed in the pop-up menu above the list of available backups (item e. in the green box in #14 of the Frequently Asked Questions *User Tip* at the top of this forum).
    If that's a possibility, boot up from your SL Install disc again, and go through the process that far. If you find two disk names listed there, select the other one and see what dates are available. If you find your recent backups, do the restore again from one of them.
    If not, reboot normally, then try the +*Browse . . .+* Option, per #17 in the Frequently Asked Questions *User Tip* at the top of this forum.
    Restore what you need from the latest backup you can find that way. That will get the most recent version of everything. You can't restore your home folder that way, but you can restore each sub-folder and it's contents that way.

  • Finding the oldest file in a directory

    I have a log directory that can have a lot of files in it. How can easily find the oldest file out of a large group of files in the directory so that I can delete it. The file name is of the form xxxx.*
    I believe I can use a filter to get a list of files in the directory eith file name xxxx.* and then go through the list one by one and check the time stamp of the file and keep the name of the oldest one I find. Is there an easier way to just have these files ordered by modification date in acending order?

    check the File class docs. There is a method called lastModified() you can write some simple code that can keep track of the file with the oldest date.

  • Select most recent file and display

    I've been considerig this and I am closer to how I expect it to work
    This is what I have so far but can't peice together just yet.
    Get the current open folder window look for the last item if shot within the last 30 secs of the creation date, if shot within 30 secs then select/highlight the file and use system events to press keystroke y using cmd and option down.(to put it on the screen in full screen) Display for 15 secs, or if esc hit then wait for next file to arrive and so on.
    If the window is closed of the current open folder then end applescript.
    This is how far I have got but can't link the ideas together well.
    set theWindow to name of front window of application "Finder"
    set theWindow to name of front window of application "Finder"
    set theFldr to path of theWindow
    tell application "Finder"
              set theContents to sort items of theFldr by creation date
              set theLastimage to (contents of item 1 of theContents) as text
      --is it within the last 30 seconds?
      -- yes, then
              tell application "System Events"
      keystroke "y" using {command down, option down}
                        delay 15
      key code 53
      --then wait for arrival of next image. and repeat.
      --if theWindow is close end applescript.
              end tell
    end tell

    Hi,
    If you don't want to use a folder action, try this :
    try
          tell application "Finder" to set currFolder to name of front Finder window
    on error
          return -- no Finder window
    end try
    set tDate to (current date) - 30
    repeat
          set b to false
          tell application "Finder"
                set fWindows to Finder windows whose it's name is currFolder
                if (fWindows is not {}) then
                      set tWind to item 1 of fWindows
                      set nFiles to document files of tWind whose creation date > tDate -- get newer files
                      set tDate to (current date)
                      if nFiles is not {} then
                            reveal nFiles
                            my selectionfullScreen(currFolder, count nFiles)
                            set b to true
                      end if
                else
                      exit repeat -- quit the script, the current Folder is closed
                end if
          end tell
          if not b then delay 5 -- no recent files, wait 5 seconds
    end repeat
    on selectionfullScreen(tName, n)
          tell application "System Events"
                tell process "Finder"
                      set frontmost to true
                      keystroke "y" using {command down, option down}
                      repeat (15 * n) times
                            tell window 1 to if (exists) and (its title is tName) then return -- the user close QuickLook
                            delay 1
                      end repeat
                      tell window 1 to if (exists) and (its title is not tName) then key code 53 -- close QuickLook after (15 seconds X (number of images))
                end tell
          end tell
    end selectionfullScreen

  • Re-opening most recent files/web sites--how can i disable this?

    when I close a window and then reopen it, or when i log out and then log back in, the most recent thing I was looking at from before immediately pops open.  That is not necessarily the way I would like it to work--didn't do that with Snow L.  How can I disable this?

    In System Preferences > General > uncheck Restore windows when quitting and re-opening apps.
    Note that this preference affects all apps.
    Regards,
    Captfred

  • Spotlight Search of Calendar only finds most recent item

    I have two future appointments named "Dentist". When I do a spotlight search for "Dentist", the results only show the most recent appointment and not both appointments.
    I have done a full reset without restoring from backup to make sure the databases were rebuilt, but I still see the same behavior. Is this expected? The apple support people say no, but I can't figure out why this is happening and don't believe new hardware would fix the problem.

    Someone noted earlier that Spotlight went only two months back in the past. But this sounds like a different issue.
    Hmm .. just did a test. Looked for a Doc appt in August and found it two days ago, the date it was on before I rescheduled it. Looking in my calendar it is shown in August, the correct date.
    Most strange!
    Later: Apparently it is searching only the Cal app of the iPhone, not Saisuke -- the third-party app I use and synchronize with Google Calendar on my MacBook. Not sure where the Cal app is getting it's info.
    Phil
    Message was edited by: w7ox

Maybe you are looking for

  • Videos Won't Play in Mobileme Gallery App

    Hi. I recently downloaded the MobileMe Gallery app. The app displays the Photo Albums and Videos in my gallery but, when I try to play the videos, I get this message: "This video can't be played on this device." The videos were created in Imovie and

  • ITunes refuses to quit on shutdown

    I am using iTunes 6.0.4(3) on a 20" iMac Power G5 OS X 10.4.5 with three AirPort Express units connected to an existing wireless Network. If iTunes is open and I shutdown, iTunes cancels shutdown and then refuses to quit (it quits and then instantly

  • Mapviewer.addImageTheme

    hi there, i'm trying to add an image to the mapviewer-bean and any time i'm receiving an internal server error message 500; -- cannot resolve addImageTheme in the java doc this method is described with the additional hint "for future purposes!". does

  • How to deauth. Photoshop CS3 on computer w/ dead network card?

    Hi, The network card on my ~4-6 years old Windows XP PC at work died and the tech guy said the network card is part of the motherboard so it would make more sense to just get a new machine instead of fixing the existing machine.  Since I will be gett

  • Boot process freezing

    I have just been given a old Mac from a friend and want to start using it. I have the Tiger OS Dvd and whenever I try to boot machine it gets to the point where the little circle goes around then always freezes at the same point (5 Oclock on the circ