Select Correct Text File - Names Changing

Eevery few hours my AS400 generates a text file. I am writing a program that will automatically take this file and convert it to an XML. The problem I am having is with the naming convention of the text file:
"IR + 6 digit number which increments by one each time a file is generated + _ + The start date and time for the file +_to_ + end date and time for the file + .txt". For example IR000002_20070528141515_to_20070528170003.txt is the name of the second file generated which started at 14:15:15 on 28/05/2007 and ended at 17:00:03 on 28/05/2007.
Each time my program runs I want it to read the latest file that has been generated. I know where the file will be found and how to select the file when it is generated with the same name each time but havnt a clue now that each file has a different name. Can anybody help? Can I use JFileChooser?

You can use the lastModified() method of the File object to your benefit:
import java.io.File;
public class FindLatestFile {
        public static File getLatest(File thisDir) throws Exception {
                long latestModDate = -1;
                File latestFile = null;
                if (!thisDir.isDirectory()) {
                        throw new Exception("Please pass in a directory.");
                File[] fileList = thisDir.listFiles();
                for (File f : fileList) {
                        if (f.lastModified() > latestModDate) {
                                latestModDate = f.lastModified();
                                latestFile = f;
                return latestFile;
        public static void main(String[] args) {
                try {
                        System.out.println("The latest file in the current directory is " +
                                        getLatest( new File(System.getProperty("user.dir") ) ) + ".");
                } catch (Exception e) {
                        e.printStackTrace();
}

Similar Messages

  • Saving/exporting issue in Windows 7-file name changes when trying to navigate

    I just got Windows 7 on my computer and am running ID CS5. The weirdest problem happens when I try to save as or export a file. The dialog box comes up and normally, I would be able to select a folder I want to navigate to just by typing the folder name, but what is happening is that the first letter goes to a folder, but upon typing the second letter, it starts changing the name of my file.
    So for example, I am saving a file ABC.indd and I go to navigate to save it in a folder called Project XYZ. When I type in "P" to get to that folder name, it jumps right to the first folder starting with P. However, upon typing "r" my file name changes from ABC.indd to "r.indd." If I kept typing, it would become "roject XYZ.PDF."
    This happens when saving as a file or if I am exporting a PDF. Our entire marketing department or 6 people was recently upgraded from XP to 7 and we all have this problem in ID. This does not happen in Illustrator or Photoshop and it has our IT department baffled. It is driving us crazy though because we make dozens of files a day and now have to manually scroll through long file structures when exporting PDFs, which is so time consuming, not to mention aggravating.
    In searching for this problem, I found another poster on a different website who has the same issue, but no one had any suggestions.

    Tell whomever is emailing the file to zip it first.

  • InDesign CS4: File names change to string of numbers

    Occasionally, one of our users will save an InDesign CS4 file, only to have the file name change.  For example, a file originally named "#kwn25501.bcbsNM.indd" was saved as "#kwn25501.bc157-1223857848."
    If the user is not aware that this has happened, things can go horribly, terribly wrong in our production environment. The "numbered" file may be missing key elements, or be somehow be corrupt in some fashion. In one case, this led us to having to reprint a job because the "numbered" file was missing a photo; somehow, that file was used (and perhaps renamed after the fact) to create the final output.
    We use Macs running InDesign CS4 6.0.5. Some of our Macs are running Tiger 10.4.11, while others are running Leopard 10.5.8. The problem seems to related to the Leopard machines, although that is not 100 percent certain at this point. All of these Macs are bound to Active Directory and save files to a Windows 2003 server. I know Adobe recommends against working on files over a network, but perhaps there is an explanation for this file renaming aside from network issues.
    Any light that can be shed on this issue will be greatly appreciated. Thanks!
    Kevin Stauffer

    Check to see if maybe your original filename is the problem.
    You may need that particular name for a workflow reason, but some of the symbols in the middle of your filename are generally not a good idea. Especially working off of a server, file names should be ONLY alpha-numeric characters, no symbols, no periods (except for the file type) and only underscores or dashes to separate words, no spaces.
    The reason is some of those symbols get picked up as machine language and all sorts of bad can happen as a result.
    Message was edited by: Michael Riordan

  • Fix variable text (File Name) when importing INDD into INDD

    More of a fix request than a new feature:
    Simply put, the variable text (File Name) shows the file extension when the document is imported into another INDD regardless of the variable text specifications in the originating document. This is unexpected and undesired.
    Please see problem description in this thread: http://forums.adobe.com/thread/489492?tstart=0

    Seconded. Currently, I don't use this variable in this way, but I can envisage future scenarios where it would be a problem.
    And it seems a strange thing to miss out on ... (why would an INDD file behave different?)

  • Pass the text file name to the command prompt using servlet

    hi to all,
    I have a HTML page that takes the user inputs. Once the user clicks on the submit button on the HTML page, these values will be capture by a servlet and then store into a text file. A new text file is generated each time the user clicks on the submit button.
    Now, i need to call a command prompt window and then pass the text file name to another program for execution. Any idea how i can pass the text file name to the command prompt???
    Thanx a lot....
    kinki

    hi, thanx 4 ur reply.
    But i not onli want to display the file name on the Tomcat command prompt. I must also able to call up a program to execute the command. If i used System.out.println(); it onli display the value on the console windows. But not executing it... anyway where i can do it???.
    thanx...
    Kinki

  • When downloading files the file name changes name?

    When I download files from yahoo email account the file name changes from actual name to securedownlad.doc. Why is this happening and how do I stop it? Is it an email client issue?
    Example:
    Original file name in email to download is called GeorgiaTechstinks.doc
    when downloaded the dl box pops up and file name has changed to securedownload.doc.
    I have to go and manually change file name back to GeorgiaTechstinks.doc
    any help would be greatly appreciated

    See here for information.
    (24629)

  • Photoshop Elements 3.0 Back-Up - File Name Change

    I currently run Photoshop Elements 3.0. When I back-up the catalog from within Photoshop, the file names are changed (i.e 100_2424.JPG to BO00012). All of my Premiere Elements 7 projects point to the original file name. If I ever lost that original JPG file, the back-up file would be recovered, but would not be recognized by Premeiere Elements, and thus not be found. Why does the file name change after back-up? How can I retain the original file name during back-up? Thanks.

    Once you have taken the backup, all the files are renamed as you mentioned in the post. Its only when you restore the catalog through File->Restore, the files are restored by the original name.

  • I have an Adobe Flash Professionals digital classroom book for CS6 and was following all steps easily until it ask me to select the text tool and change it from classic to tfl in the property inspector. I looked and all that drops down is dynamic, static,

    I have an Adobe Flash Professionals digital classroom book and was following all steps easily until it ask me to select the text tool and change it from classic to tfl in the property inspector. I looked and all that drops down is dynamic, static, and input. Where is the TFL and Classic ? I watched adobe learning center but he was using CS5. Can anyone please help?

    Hi,
    Do you use Flash CS6 to follow the instructions in the classroom book? If yes, then you can find it under text drop down for an AS3 Document as shown below
    If you follow the instruction in Flash CC or Flash CC2014 then you will not find this option as this is deprecated.
    Thanks!
    Mohan

  • Correction pdf file wont change to other files to load resume

    correction  pdf files wont change to word doc files

    Hi denniswhite56,
    I see that you have an ExportPDF subscription. Are you having trouble logging in? Or trouble converting files after you've logged in?
    Best,
    Sara

  • File name changes when I sync videos

    As title says, when ever I load a video into my 3Gs Iphone the file name changes to a numerical one.
    How do I keep the original file name?
    As it is I can only sync 1 video at a time then rename it before adding another.

    Oops, Just realised I put this n the wrong forum. Just to clarify this is prerecorded video files.

  • CS4 Photoshop.exe file name changes

    Has anyone had the CS4 Photoshop.exe file change names? I have had this happen on a couple of computers, one machine it happened twice. When CS4 is installed, the Photoshop file name is Photoshop.exe, at some point, the file name changes to PHOTOSHOP_CS4.EXE. I'm going to check with our sys admins to make sure they aren't doing some software push that might be changing it, but thought I would post here in case it was a known issue.

    When you find the culprit you might let him know that different Photoshop versions always live in different Program Files subfolders.
    -Noel

  • IPhoto file names changed

    I have just noticed that in several of my events the underlying file name of several imported photos has been changed to my assigned Title.  Since I didn't think Apple provided a way in iPhoto for Mac to change the file name, and I am not digging into the file structure of iPhoto, I can't change the file name back to that assigned by the camera (and I don't necessarily know it anyway).  I see no obvious reason why specific file names were changed.  Is there some non-obvious way to change file names that I accidentally stumble upon?

    iPhoto 9.4.3.  Not sure what you mean by history.  It has been in use for some time.  No other obvious problems.  The file name changes, at least that I have noticed, are from this year and, in particular, this past week.  One other observation is that I only happened to notice because I exported a group of photos and saw that a few of the exported names did not have the camera assigned names and then I looked back at iPhoto (hovering the cursor over the title - which gives the file name).  Again, the files were exported as a group and no obvious reason for something to change for one rather than another file.  It is possible the change took place when I exported the photos rather than earlier as I had no reason to check.

  • Identifying text file names and importing on single Excel sheet

    Hey!
    Does anybody can help me with Excel VBA macro code in order to import data from text files into single Excel spread sheet? I want to create User Form where user can select start and end date of interest and macro code will import
    bunch of text files depending on user demands...
    My text files are named: 20130619004948DataLog.txt (meaning: yyyy mm dd hh mm ss). Text file contains recordings for each 15 seconds... It would be great to omit time tail (meaning that user can only specify date). Text files for one day of interest (I have
    text files covering whole year):
    20130619004948DataLog.txt
    20130619014948DataLog.txt
    20130619024948DataLog.txt
    20130619034948DataLog.txt
    20130619044948DataLog.txt
    20130619054948DataLog.txt
    20130619064948DataLog.txt
    20130619074948DataLog.txt
    20130619084948DataLog.txt
    20130619094948DataLog.txt
    20130619104948DataLog.txt
    20130619114948DataLog.txt
    20130619124948DataLog.txt
    20130619134948DataLog.txt
    20130619144948DataLog.txt
    20130619154948DataLog.txt
    20130619164948DataLog.txt
    20130619174948DataLog.txt
    20130619184948DataLog.txt
    20130619194948DataLog.txt
    20130619204948DataLog.txt
    20130619214948DataLog.txt
    20130619224948DataLog.txt
    20130619234948DataLog.txt
    Option Explicit
    Sub SearchFiles()
    Dim file As Variant
    Dim x As Integer
    Dim myWB As Workbook
    Dim WB As Workbook
    Dim newWS As Worksheet
    Dim L As Long, t As Long, i As Long
    Dim StartDateL As String
    Dim EndDateL As String
    Dim bool As Boolean
    bool = False ' to check if other versions are present
    StartDateL = Format(Calendar1, "yyyymmdd")
    EndDateL = Format(Calendar2, "yyyymmdd")
    ' I am using Userform asking user to select the date and time range of interet,
    ' However, I want to use only the date to filter the files having the name with that particular date
    file = Dir("c:\myfolder\") ' folder with all text files
    ' I need assistance with the following part:
    '1) How to filter and select the files between StartDateL and EndDateL_
    '(including files with that dates as well)?
    While (file <> "")
    If InStr(file, StartDateL) > 0 Then 'Not sure if the statements inside parenthesis is correct
    bool = True
    GoTo Line1:
    End If
    file = Dir
    Wend
    Line1:
    If Not bool Then
    file = "c:\myfolder\20130115033100DataLog.txt" 'Just for a test that the code works as intended
    End If
    'This part for the selected text files to be loaded on a single Excel Sheet.
    Set myWB = ThisWorkbook
    Set newWS = Sheets(1)
    L = myWB.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row
    t = 1
    For x = 1 To UBound(file)
    Workbooks.OpenText Filename:=file(x), DataType:=xlDelimited, Tab:=True, Semicolon:=True, Space:=False, Comma:=False
    Set WB = ActiveWorkbook
    WB.Sheets(1).UsedRange.Copy newWS.Cells(t, 2)
    t = myWB.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Row + 1
    WB.Close False
    Next
    myWB.Sheets(1).Columns(1).Delete
    Application.ScreenUpdating = False
    Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End Sub

    - Make a new Excel file
    - Open the VBA editor
    - Add a Userform
    - Place 2 text boxes and 1 command button on that form
    - Paste all code below into the code module of the form
    - Download this file:
    https://dl.dropboxusercontent.com/u/35239054/FileSearch.cls
    - In the VBA editor press CTRL-M and import that file
    - Save the Excel file in the directory that contain your text files
    - Run the form
    You can format the columns of the sheet as you like, e.g. column E:H should be a number with 5 decimal places. The top row can contain some headings. My code did not affect the formatting or the headings.
    Andreas.
    Option Explicit
    Private Sub UserForm_Initialize()
    'Just a sample
    Me.TextBox1.Value = FormatDateTime(Now, vbGeneralDate)
    Me.TextBox2.Value = FormatDateTime(Now, vbShortDate)
    End Sub
    Private Sub CommandButton1_Click()
    Dim StartDate As Date, EndDate As Date
    Dim FS As New FileSearch
    Dim R As Range
    Dim ThisFile As Variant
    Dim ThisDate As Date
    Dim Data As Variant
    Dim Count As Long
    'Be sure we have 2 dates
    If Not IsDate(Me.TextBox1.Value) Then
    Me.TextBox1.SetFocus
    MsgBox "No start date"
    Exit Sub
    End If
    If Not IsDate(Me.TextBox2.Value) Then
    Me.TextBox2.SetFocus
    MsgBox "No end date"
    Exit Sub
    End If
    'Convert to real dates
    StartDate = CDate(Me.TextBox1.Value)
    EndDate = CDate(Me.TextBox2.Value)
    'Time part given?
    If Fix(EndDate) = EndDate Then
    'No include all files for this day
    EndDate = EndDate + TimeSerial(23, 59, 59)
    End If
    'Correct order?
    If StartDate > EndDate Then
    ThisDate = EndDate
    EndDate = StartDate
    StartDate = ThisDate
    End If
    With FS
    'Same path as our file
    .LookIn = ThisWorkbook.Path
    .FileName = "*DataLog.txt"
    'Search all files sort by file name
    If .Execute(msoSortByFileName, msoSortOrderAscending) = 0 Then
    MsgBox "No data files found in " & .LookIn
    Exit Sub
    End If
    'Clear previous data
    Set R = Range("A2").CurrentRegion
    If R.Row < 2 Then Set R = R.Offset(1)
    R.ClearContents
    'Show the user that we are working
    Application.Cursor = xlWait
    DoEvents
    For Each ThisFile In .FoundFiles
    'Get the date from the file name
    ThisDate = Filename2Date(ThisFile)
    'Between our dates?
    If (ThisDate >= StartDate) And (ThisDate <= EndDate) Then
    'Import at the end of the data
    Set R = Range("A" & Rows.Count).End(xlUp).Offset(1)
    Data = ReadCSV(ThisFile)
    R.Resize(UBound(Data) + 1, UBound(Data, 2) + 1) = Data
    Count = Count + 1
    End If
    Next
    End With
    'Done
    Application.Cursor = xlDefault
    If Count = 0 Then
    MsgBox "No files match your dates"
    Else
    MsgBox Count & " files imported"
    'Hide the form
    Me.Hide
    End If
    End Sub
    Private Function Filename2Date(ByVal Fullname As String) As Date
    'Convert e.g "C:\20130601142648DataLog.txt" to the date "01.06.2013 14:26:48"
    Dim i As Long, j As Long
    i = InStrRev(Fullname, "\")
    If i > 0 Then Fullname = Mid(Fullname, i + 1)
    Fullname = JustNumbers(Fullname)
    If Len(Fullname) <> 14 Then Exit Function
    Filename2Date = _
    DateSerial(Mid(Fullname, 1, 4), Mid(Fullname, 5, 2), Mid(Fullname, 7, 2)) + _
    TimeSerial(Mid(Fullname, 9, 2), Mid(Fullname, 11, 2), Mid(Fullname, 13, 2))
    End Function
    Private Function JustNumbers(ByVal What As String) As String
    'Return only numbers from What (by Rick Rothstein)
    Dim i As Long, j As Long, Digit As String
    For i = 1 To Len(What)
    Digit = Mid$(What, i, 1)
    If Digit Like "#" Then
    j = j + 1
    Mid$(What, j, 1) = Digit
    End If
    Next
    JustNumbers = Left$(What, j)
    End Function
    Private Function ReadCSV(ByVal Fullname As String) As Variant
    'Read a CSV file into an array
    Const LDelim = vbCrLf 'Line delimiter
    Const FDelim = ";" 'Field delimiter
    Dim hFile As Integer
    Dim Buffer As String
    Dim Lines, Line, Data
    Dim i As Long, j As Long
    'Be sure the file exists
    If Dir(Fullname) = "" Then Exit Function
    'Open and read all data
    hFile = FreeFile
    Open Fullname For Binary Access Read As #hFile
    Buffer = Space(LOF(hFile))
    Get #hFile, , Buffer
    Close #hFile
    'Split into lines
    Lines = Split(Buffer, LDelim)
    'Split the first line and prepare the output
    'Note: I assume that all lines have the same number of fields
    Line = Split(Lines(0), FDelim)
    ReDim Data(0 To UBound(Lines), 0 To UBound(Line))
    For i = 0 To UBound(Lines)
    Line = Split(Lines(i), FDelim)
    For j = 0 To UBound(Line)
    'Parse the fields
    If IsDate(Line(j)) Then
    Data(i, j) = CDate(Line(j))
    ElseIf IsNumeric(Line(j)) Then
    Data(i, j) = CDbl(Line(j))
    Else
    Data(i, j) = Line(j)
    End If
    Next
    Next
    ReadCSV = Data
    End Function

  • Add date to new text file name and generic text in body

    Okay, I hope this is the right forum. To help manage and keep track of incoming assets/files and I created an Automator workflow with the following: "Get Selected Finder Items → Get Folder Contents → New Text File (w/Show this action when the workflow runs so I can give a unique name).
    This creates a text file with the folder contents listed in the body.
    I would like to know if I can do two things:
    1. Automatically add a date/time stamp to the Save as field so it will automatically have a unique file name?
    2. I also want to add text before the listed contents within the text file. (e.g.: Let's say the folder contents are Volumes/Mac HD/Generic_movie.mov. I want the final text to read:
    "The following file has been moved to the local volume at: Volumes/Mac HD/Generic_movie.mov"
    Is there a way to accomplish either one or both of these with Automator or AppleScripts?
    Thanks.

    I would like to know if I can do two things...
    This might address your first concern:
    *1) Get Selected Finder Items*
    *2) Get Folder Contents*
    *3) New Text File* -- select a destination folder and check *Show Action When Run*
    *4) Rename Finder Items:*
    Choose *Add Date or Time* from the popup
    Date/Time: select Created, Modified, or Current - Format: *Month Day Year*
    Where: *After name* - Separator: *Forward Slash*
    Separator: Space - check *Use Leading Zeros* (optional)
    *5) Rename Finder Items:*
    Choose *Add Text* from the popup
    Add: *" at"* -- put a leading space before "at" (without the quotes), and select *after name*.
    *6) Rename Finder Items:*
    Choose *Add Date or Time*
    Date/Time: Current - Format: *Hour Minute Second*
    Where: *After name* - Separator: Dash
    Separator: Space - check *Use Leading Zeros* (strongly recommended)
    +--- End of Workflow ---+
    Save the workflow as an application and use it as a droplet. Drop a desired folder onto the saved applet and enter a name when the dialog appears. The new text file, which will be found in the destination folder, should be appended with a date and time stamp, e.g., *"My Folder List 7/8/2010 at 23-54-09"*
    Tested using Mac OS 10.4.11 and Automator v. 1.0.5
    Good luck; hope this helps.

  • PDF file names changed in iBooks with iOS 8 upgrade

    I just downloaded iOS 8 on my iPad air. This has caused the file names of all of my PDFs in iBooks to revert to their original file name when I downloaded the file, not the custom file names I gave them after downloading the files. In the list of files it shows the original PDF name; however, in the banner above the open file it shows the custom name I gave it. How do I easily change the file names back to the custom file names that I renamed after the downloads?  Essentially I want to have the file name in the banner replace the file name in the list. I have thousands of files, so doing them one at a time is not practical.  Thanks for your help. 

    The strange thing is: the correct name is still available in the headline of the pdf file when opened. its only wrong in the overview...

Maybe you are looking for