1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB Scirpting Error

Discussion in 'Software Development' started by neash83, Feb 17, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. neash83

    neash83 Thread Starter

    Joined:
    Feb 11, 2007
    Messages:
    13
    Hello,

    I have this VB script, but it doesnt seem to be working can anyone tell me where I have gone wrong

    Dim filesys, demofolder, fil, filecoll
    Set filesys = CreateObject( "Scripting.FileSystemObject" )
    Set demofolder = filesys.GetFolder("C:\AZ\A")
    Set filecoll = demofolder.Files

    Dim counter, foldername, filepath, filename
    counter = 0

    For Each fil in filecoll
    filename = split(fil.name,".")
    foldername = "C:\AZ\A" & thefile(0) & "\"

    filepath = "C:\AZ\A" & fil.name

    filesys.CreateFolder(foldernam...
    filesys.MoveFile filepath, foldername
    counter = counter + 1
    Next

    Set filesys = "C:\AZ\A"

    WScript.Echo("Folders Created:" & counter)


    Thanks
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    So you are basically trying to create a seperate folder for each file in a directory and then move the file into it's own folder? Did you get this sorted yet?

    Regards,
    Rollin
     
  3. neash83

    neash83 Thread Starter

    Joined:
    Feb 11, 2007
    Messages:
    13
    Hello,

    I didn't get it sorted, I have made a little progress though.

    The orignal error was relating to line 15 I believe where it just read folderna....

    Obviously I just needed to put "foldername" there.

    Now I have a new error coming up when running it relating to about line 11 where it reads

    foldername = "C:\AZ\A" & thefile(0) & "\"

    The error it is saying is relating to the piece of code which says "thefile"

    And yes what you described is what I am trying to do.

    Thanks
     
  4. Mosaic1

    Mosaic1

    Joined:
    Aug 17, 2001
    Messages:
    7,486
    Because there is no such thing as theFile.

    You cannot set filsys as a string like you did at the end. That's the File System Object. Set it to nothing at the end. Ususally it is named fso or objfso



    Now what if a filename has more than one period? You might consider using instrrev to look for the last period and then mid.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/544797

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice