Solved

Filenames

Posted on 2012-03-23
7
421 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

914 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

13 Experts available now in Live!

Get 1:1 Help Now