1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

List All Files in Folder using VBScript

Discussion in 'Visual Basic [VB]' started by pradeep, Jun 24, 2006.

  1. bettlejus

    bettlejus Banned

    Hello, I have the following code for sending a mail with Outlook, my problem is that I need to sedn this mail 4 times a day with a diferent file, sometimes with 2 files in attach, and I am modifying this everytime with the name of the file, not much help there

    I was wondering how to tell the script to look for files in a folder and attach everything it finds to the mail

    Can anyone help me?

    Dim objOutlk
    Dim objMail
    Dim strMsg
    Const olMailItem = 0
    Set objOutlk = createobject("Outlook.Application")
    Set objMail = objOutlk.createitem(olMailItem)
    objMail.To = "test@company.com"
    objMail.cc = ""
    objMail.subject = "Subject "
    strMsg = "Hello,"
    objMail.body = strMsg
    Set objMail = nothing
    Set objOutlk = nothing
  2. andorosfire

    andorosfire New Member

    Does anyone know how to perform this same task on a Mac running OS X.5?
  3. donkey

    donkey New Member

    hi pradeep
    this is a perfect useful script exmple to me, if is it possible to import any reg files in a folder like regedit /i some_files.reg instead of create filelist.txt, that I looking for, I'm very pleased do you would help me :)
  4. Jeff Greener

    Jeff Greener New Member

    You need to declare an undimensioned array, and then initialize it at the top:
    Dim myresults()
    ReDim myresults(0)

    then replace the output portion:
    with these two lines:

    redim Preserve Myresults(ubound(Myresults)+1)

    This will leave you with an array full of the results and one empty slot at the end.
  5. Kiru

    Kiru New Member

    Hi I am Kiru. i went through these codes. Excellent.

    However, i have a situation here and i would need your help in this regard.

    I have a folder and i have so many sub folders. i getting the folder names in an excel file based on the last modified date.

    This excel file gets updated every hour.

    so, now, i want to check the current date with the last modified date.
    if yes, then i have to check for the name of the folder (which is usually employees name).

    I have a data base in excel file where i have fed employees name and his email address.

    if a last modified date of a folder indicates a current date, i need to shoot an email to that particular person based on the database cells.

    i know it is possible to write a scirpt in excel but i am not familiar with the codes.

    can you help me.
  6. edytharceo

    edytharceo New Member

    This site is really great, i am glad that there is a site, thread like this. The information here is very helpful.
  7. Bacaryu

    Bacaryu New Member

    Hello, I'm new to vb scripting

    I need something like this code but with addition of text to the txt output file.

    so the script should check for every file in the folder and give an output of :

    RESTORE LOG NewDatabase
    FROM DISK = ''D:\BackupFiles\TestDatabase_TransactionLogBackup1.trn'

    RESTORE LOG NewDatabase
    FROM DISK = ''D:\BackupFiles\TestDatabase_TransactionLogBackup2.trn'

    Can somebody help me with that.

    I don't think it should be hard to do, I only don't know how exactly.
  8. sasaa86

    sasaa86 New Member

    is there a way to only save the file name and not the extension

    I use it to list my mp3's

    (there all the same type of files ".mp3")
  9. Impala

    Impala New Member


    I get a list of folders and subfolders in the target folder.
    What I like is this scrip that displays all files in the target folder and all the sub and sub sub folders also in one file output.

    Thanks Roald
  10. codvb

    codvb New Member


    I adapted the code for the list folder and all sub-folders but the error below appears when I run the file:

    Line: 26
    Char: 5
    Error: Expected statement
    Code: 800A0400
    Source: Microsoft VBScript compilation error

    I need to list the all filenames in each folder too but, I'm beginner in VBScript! Can you help me? What I have to do?

    Adapted Code:
    On Error Resume Next
    Const WINDOW_HANDLE = 0
    Const BIF_EDITBOX = &H10
    Const BIF_NONEWFOLDER = &H0200
    Set objShell = CreateObject("Shell.Application")
    Set wshShell = CreateObject("WScript.Shell")
    Set objFSO   = CreateObject("Scripting.FileSystemObject")
    strPrompt     = "Please select the folder to process."
    strTargetPath = wshShell.SpecialFolders("MyComputer")
    strFolderPath = Browse4Folder(strPrompt, intOptions, strTargetPath)
    Set objNewFile = objFSO.CreateTextFile(strFolderPath & "\ListaMP3.txt", True)
    Set objFolder  = objFSO.GetFolder(strFolderPath)
    Set objColFolders = objFolder.SubFolders
    For Each tfolder In objColFolders
    [I]    objColFolders = tfolder.SubFolders
        GoTo AllFolders[/I]
    [B]'END HERE[/B]
    Function Browse4Folder(strPrompt, intOptions, strRoot)
        Dim objFolder, objFolderItem
        On Error Resume Next
        Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
        If (objFolder Is Nothing) Then
        End If
        Set objFolderItem = objFolder.Self
        Browse4Folder = objFolderItem.Path
        Set objFolderItem = Nothing
        Set objFolder = Nothing
    End Function
  11. kaiwen21

    kaiwen21 New Member

    Awesome script thanks

    Is it possible however to split the filename into different columns in an excel table.

    for e.g. the file is "001 - his name is known.mkv"

    and want to split it as follows:
    Column A: 001
    Column B: his name is known

    and drop the file extension from the file list
  12. AutosysR11

    AutosysR11 New Member


    I am beginner in vbscript. Can someone help me to resolve my problem. I was trying to export all files in C:\windows with the file extension of .log and will list the file to Filelist.txt under the same path (c:\windows).
  13. pramodmhn

    pramodmhn New Member

    I will do this way:
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set Folder = objFSO.GetFolder(".")
    Set NewFile = objFSO.CreateTextFile(Folder&"\FileList.txt", True)
    For Each File In Folder.Files
    'sNewFile = File.Name'including extension
    NewFile.WriteLine(left(File.Name,(len(File.Name)-4)))'exclude extenstion

Share This Page