?
Solved

Filenames

Posted on 2012-03-23
7
Medium Priority
?
430 Views
Last Modified: 2012-03-23
I get .dat files everyday I need to process.
I need to get the file from the directory, then move it to another.
How can I identify the correct file.

????????-201203230837082380.dat

From  digits 10 – 17 date YYYYMMDD

        Const ForReading = 1
        Const ForWriting = 2

        Dim strFolder As String
        Dim getDatFileName As String

        Dim oFSO
        Dim oFolder
        Dim oFile

        strFolder = Dts.Variables("OOH_Path").Value.ToString
        'strFolder = Dts.Variables("ftp").Value.ToString

        oFSO = CreateObject("Scripting.FileSystemObject")

        If oFSO.FolderExists(strFolder) Then
            MsgBox("strFolder" & strFolder)

            oFolder = oFSO.GetFolder(strFolder)

            For Each oFile In oFolder.Files
                If LCase(Right(oFile.Name, 4)) = ".dat" Then
                    getDatFileName = oFile.Name
                    MsgBox(getDatFileName)

                End If

            Next

        End If
0
Comment
Question by:aneilg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1580 total points
ID: 37757006
Try this:


                If LCase(Right(oFile.Name, 4)) = ".dat" Then
                    getDatFileName = oFile.Name
                    MsgBox(getDatFileName)

                End If

IF left(split(getDatFileName ,"-")(1),8) = format(date,"yyyymmdd") then
    msgbox "Today's File is: "  & getDatFileName
End if
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37757017
That's assuming a consistent format as you have shown with a "dash" seperating a prefix from the date/time portion of the file name.
0
 

Author Comment

by:aneilg
ID: 37757031
thanks for quick responce, but i have other files in the folder the similar naming conventions, i need to be exact. eg ????????-201203230837082380.txt.

also i am using ssis script task manager, and evertime i use the date i get an error. 'of required when specifying type argument.

thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aneilg
ID: 37757059
thanks this works.


  sDate = Right("00" & Year(Now()), 4) & Right("0" & Month(Now()), 2) & Right("00" & Day(Now()), 2)
        sDateString = sDate


        oFSO = CreateObject("Scripting.FileSystemObject")

        If oFSO.FolderExists(strFolder) Then
            'MsgBox("strFolder" & strFolder)

            oFolder = oFSO.GetFolder(strFolder)

            For Each oFile In oFolder.Files
                If LCase(Right(oFile.Name, 4)) = ".dat" Then

                    getDatFileName = oFile.Name
                    'MsgBox(getDatFileName)

                    If Left(Split(getDatFileName, "-")(1), 8) = sDateString Then
                        MsgBox("Today's File is: " & getDatFileName)
                    End If

                End If

            Next

        End If
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37757071
Sweet.  
Just in explanation, the Split function parses your filename, looking for a "-" and then compares the first 8 characters following the dash to todays date.
0
 

Author Comment

by:aneilg
ID: 37757093
thanks for your help, perfect.

also thanks for the explanation.
0
 

Author Closing Comment

by:aneilg
ID: 37757097
perfect, And quick responce.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question