Solved

Filenames

Posted on 2012-03-23
7
413 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 395 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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now