We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Need to minus one second to file name and display - HELP!

Kit_Kat111
Kit_Kat111 asked
on
Medium Priority
262 Views
Last Modified: 2010-04-23
Okay all of this is working but now I need to get button called "previous" to work. I need to minus one second to the file and then display the pictures with that change. I really have no idea how to do this.

file is broken up like this:
Cam1-20060224165650-01.jpg

Cam1     -2006   02       24         1656  50                         -01.jpg
(camera)- year month  day and military time with seconds -01.jpg

so adding it will be Cam1-200602224165651-01.jpg


Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" & DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy", Nothing).ToString("M-d") & "\Cam {0}\Cam{0}" & cmbTime.Text.Substring(cmbTime.Text.IndexOf("-"))

        For i As Integer = 1 To 8

            Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" & i)
         
            If Not pcb Is Nothing Then

                If File.Exists(String.Format(folder, i)) Then
                    pcb.Image = Image.FromFile(String.Format(folder, i))
                Else
                    pcb.Image = Image.FromFile("C:\Projects\Darryl\Queue Review Files\noimage.jpg")
                End If
            End If

        Next i
Comment
Watch Question

Commented:
If you have the date object ..
just subtract 1 second frmo it
like

Dim oneSecondLessDate As Date = originalDate.Subtract(New TimeSpan(0, 0, 1))

Commented:
Overall it is like

Dim originalDateAs Date = DateTime.ParseExact("20060224165650", "yyyyMMddHHmmss", Nothing)
Dim oneSecondLessDate As Date = originalDate.Subtract(New TimeSpan(0, 0, 1))

Author

Commented:
Actually I just want to add a 1 to the end section of the file name, not an actual date or time.


Cam1-20060224165650-01.jpg
Cam1     -2006   02       24         1656  50                         -01.jpg

Sorry for the confusion.
                                                         +1

Commented:
Is this what you are trying to do?

        Dim file1 As New IO.FileInfo("c:\TestFolder\Cam1-20060224165650.jpg")
        Dim File2 As New IO.FileInfo(IO.Path.Combine(IO.Path.GetDirectoryName(file1.FullName), IO.Path.GetFileNameWithoutExtension(file1.FullName) & "-01" & IO.Path.GetExtension(file1.FullName)))

        MsgBox(file1.FullName & vbCrLf & File2.FullName)
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I believe that this is what you are after:

Imports System.Text.RegularExpressions

Public Class FileOperations

  Public Shared Function IncrementFileName(ByVal fileName As String) As String

    ' Example:  Rename Cam1-20060224165650-01.jpg to Cam1-20060224165650-02.jpg
    Dim pattern As String = "(?<file>Cam\d-\d{14}-)(?<index>\d{2})(?<ext>[A-Za-z.]+)"

    Dim match As Match = Regex.Match(fileName, pattern)

    If match.Success Then
      Dim file As String = match.Groups("file").Value
      Dim index As Integer = Val(match.Groups("index").Value)
      Dim ext As String = match.Groups("ext").Value

      fileName = file & (index + 1).ToString("00") & ext

    End If

    Return fileName

  End Function

End Class

Sample:
    MsgBox(FileOperations.IncrementFileName("Cam1-20060224165650-01.jpg"))

Bob
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Simpler form without regular expressions:

  Private Function IncrementFileName(ByVal fileName As String, ByVal start As Integer, ByVal length As Integer) As String

    Dim builder As New System.Text.StringBuilder(fileName)
    Dim index As Integer = Val(fileName.Substring(start, length)) + 1

    builder.Remove(start, length)
    builder.Insert(start, index.ToString("00"))

    Return builder.ToString()

  End Function

Sample:
   MsgBox(IncrementFileName("Cam1-20060224165650-01.jpg", 20, 2))

Bob

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Sorry I haven't forgotten about this question just have been dragged away on something unexpected. I will try your suggestion and post back tomorrow.

Thank you for your assistance with my problem, and also for your patience.

Author

Commented:
Thank you very much!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.