Solved

Filenames

Posted on 2012-03-23
7
427 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 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

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!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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