Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filenames

Posted on 2012-03-23
7
Medium Priority
?
443 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

810 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