Announcement

Collapse
No announcement yet.

Can someone tell me what is wrong with this script?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can someone tell me what is wrong with this script?

    Code:
    strComputer = "."
    const forwriting = 2
    set objfso = createobject("Scripting.filesystemobject")
    set objfile = objfso.opentextfile("c:\deletemp3.bat", forwriting)
    set objwmiservice = getobject ("winmgmts:{impersonationlevel=impersonate}!\\" & strComputer & "\root\cimv2")
    set colfiles = objwmiservice.execquery ("Select *from CIM_Datafile where extension = 'mp3'")
    for each objfile in colfiles
    var = objfile.name
    wscript.echo var
    objfile.write var
    Next
    objfile.close
    It lists all the mp3's on my computer (and yes I have already got a file called deletemp3.bat in my c:\ drive) but it wont write the results of the file scan to my text file!

    I get this error:

    Code:
    C:\Documents and Settings\Chris\Desktop\filefinder.vbs(12, 1) Microsoft VBScript  runtime error: Object doesn't support this property or method: 'objfile.write'
    But i can put a string into a variable and it writes that!! Hmmm!??
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

  • #2
    You are using objfile for two different things: the output file, and the filenames from the collection. You are overwriting the output file object with something else!

    Comment


    • #3
      You are using ObjFile twice, for different reasons - As wkasdo says

      I tried your script and changed the above but i still couldn't get it to work. I created this but it only searches all subfolder under the C drive.

      set objfso = createobject("Scripting.filesystemobject")
      Set FileSet=GetObject("winmgmts:").ExecQuery("select * from CIM_DataFile where Drive = 'C:' AND Extension = 'mp3'")
      set objfile = objfso.opentextfile("c:\deletemp3.bat", 2)

      For Each File In FileSet
      objFile.WriteLine File.Name

      next
      objFile.close

      Topper
      * Shamelessly mentioning "Don't forget to add reputation!"

      Comment


      • #4
        This forums are ACE!! You guys rock! Many thanks both of you!

        Server 2000 MCP
        Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment


        • #5
          You're welcome mate.
          * Shamelessly mentioning "Don't forget to add reputation!"

          Comment


          • #6
            And I ask myself... What's wrong with:
            Code:
            c:
            cd \
            del /s *.mp3 > c:\mp3delete.log
            I realize that VBS is fancy, but sometime plain old good CMD sledgehammer does the job better
            Guy Teverovsky
            "Smith & Wesson - the original point and click interface"

            Comment


            • #7
              Originally posted by guyt
              And I ask myself... What's wrong with:
              Code:
              c:
              cd \
              del /s *.mp3 > c:\mp3delete.log
              I realize that VBS is fancy, but sometime plain old good CMD sledgehammer does the job better
              Very nice! But where does Tony says that he wants to remove his mp3 collection?

              Comment


              • #8
                I read between the lines
                Code:
                set objfile = objfso.opentextfile("c:\deletemp3.bat", forwriting)
                See this "c:\deletemp3.bat" ? [/quote]
                Guy Teverovsky
                "Smith & Wesson - the original point and click interface"

                Comment


                • #9
                  Good point!

                  Comment


                  • #10
                    Its true! But its not my mp3 collection i want to delete... its my users!

                    Plus i wanted the list first so that i could go through and see if there was anything of 'educational' use before i deleted the students files.
                    Server 2000 MCP
                    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                    Comment


                    • #11
                      Would this be for YOUR "educational" use?
                      1 1 was a racehorse.
                      2 2 was 1 2.
                      1 1 1 1 race 1 day,
                      2 2 1 1 2

                      Comment


                      • #12
                        Originally posted by tonyyeb
                        Its true! But its not my mp3 collection i want to delete... its my users!

                        Plus i wanted the list first so that i could go through and see if there was anything of 'educational' use before i deleted the students files.
                        To get the listing:
                        Code:
                        c:
                        cd \
                        dir /s *.mp3 > c:\mp3list.txt
                        Guy Teverovsky
                        "Smith & Wesson - the original point and click interface"

                        Comment


                        • #13
                          Thanks for that Guy... i did end up resorting to dir as the vbs script decided to crash scanning 65gb of student data.

                          The educational use is not mine (but my coworkers do like to take a 'backup' of songs they like!) - the students may have stuff they have composed for A-level music. But i decided to say they can have it off the backup if they needed it!

                          Saved 7gb deleting exe's, mp3's and mpg's. Backups now work again... but for how long!!!???
                          Server 2000 MCP
                          Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                          Comment

                          Working...
                          X