Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: if not exist <filename> bad-command  (Read 3047 times)

0 Members and 1 Guest are viewing this topic.

CameronY

    Topic Starter


    Intermediate

    if not exist <filename> bad-command
    « on: December 05, 2007, 08:28:38 PM »
    Hi All,

    Need to create a batch job to perform the following:
    • Check if a file/multiple files exist/s
    • Size of file > 1kb
    • Creation time of file < 24hrs old

    Not sure how crude such a script should be.
    Any suggestions?

    Cheers,
    Cameron

    Dusty



      Egghead

    • I could if she would, but she won't so I don't.
    • Thanked: 75
    • Experience: Beginner
    • OS: Windows XP
    Re: if not exist <filename> bad-command
    « Reply #1 on: December 06, 2007, 12:07:27 AM »
    Homework ???
    One good deed is worth more than a year of good intentions.

    CameronY

      Topic Starter


      Intermediate

      Re: if not exist <filename> bad-command
      « Reply #2 on: December 06, 2007, 01:47:01 AM »
      Hi Dusty,

      Actually no (but to be that young again!)
      Task was given to me by the boss, just to interupt my PCI work.
      When I posted the query; thought sadly that the question might be seen as some form of homework.
      I've not done work with timestamps or filesizes before, hence the question.  And I've had my hand out of DOS scripting for a little while now.

      Any help/direction appreciated.

      Cheers,
      Cameron

      TheManFrom



        Rookie

        Re: if not exist <filename> bad-command
        « Reply #3 on: December 06, 2007, 08:46:57 AM »
        Heres a VBScript that will do the job
        open note, copy and paste the script below, save as something.vbs
        open command prompt, type: cscript something.vbs filename
        where the filename is the file you want to check. This needs to include the full path.

        If you want to check mulitple files, you could create a batch file which calls something.vbs for as many files as you need


        '-----------------------------------------------------
        Set objArgs = WScript.Arguments
        If WScript.Arguments.Count < 1 Then
           wscript.echo "Usage: cscript scriptname.vbs drive:\path\filename"
           wscript.quit
        Else
           StrFile = wscript.arguments.item(0)
        End if

        Dim fsoFile
        Set fsoFile = CreateObject("Scripting.FileSystemObject")

        If fsofile.FileExists(StrFile) Then
           Set objFile = fsoFile.GetFile(StrFile)

           sName = objFile.Name
           sCreated = objFile.DateCreated
           sSize = objFile.Size   

           If sSize > 1024 Then   'Check Size
              Age = DateDiff("d", sCreated, Date())   'Get Age difference
                 If Age > 1 Then    'Check date is greater than 1 day
                    wscript.echo objFile.Name
                    wscript.echo objFile.Size
                    wscript.echo objFile.DateCreated   
                 End If
           Else
              wscript.echo "Not met the criteria"
                 
           End If
        End If

        set objfile = nothing
        set fsofile = nothing
        '-----------------------------------------------

        CameronY

          Topic Starter


          Intermediate

          Re: if not exist <filename> bad-command
          « Reply #4 on: December 06, 2007, 04:07:21 PM »
          Many thanks TheManFrom,

          Spent a few hours stumbling with the old scripting last night - sad when you forget so much of it.
          Seems that to perform the task purely as a MSDOS/NT script would be a painful challenge.
          Is VBScripting becoming (or is now) more the mainstream ?

          Cheers,
          Cameron

          TheManFrom



            Rookie

            Re: if not exist <filename> bad-command
            « Reply #5 on: December 07, 2007, 03:22:32 AM »
            Yes I think VBS is the way forward for admin tasks. DOS is great but has its limitations which is where I think VBS comes in handy
            Anyways glad I could help.

            Wolfmagi



              Rookie

            • Beautiful Wolf
              Re: if not exist <filename> bad-command
              « Reply #6 on: December 07, 2007, 09:47:08 AM »
              is there a particular program you need to write VBscript? My school has "Object oriented Turing"
              but I want to write this at home, and the computer I use at home, doesn't have internet. . .
              can I just use notepad for Visual Basic? is there any online tutorials? (I forget the strings things. . .
              eg. 


              var:String
              var:name
              var:pass
              cls
              LOOP
              put "what is your username"
              get name
              put "what is your password
              get pass
              exit when pass = "wood" or pass = name
              end loop

              that is Turing (except with a fault in the "Var" block at top. . .
              I can't seem to get that to work right. . . anyway can you write stuff like this in
              NOTEPAD?? (on a 10yr old computer?? with no internet. .)

              Please, these questions are important to me lol. . .

              TheManFrom



                Rookie

                Re: if not exist <filename> bad-command
                « Reply #7 on: December 07, 2007, 11:06:18 AM »
                VBScript is like a cut down version of visual basic and has the advantage of like dos batch file, you can simply open a text editor like notepad, add your script and instead of .bat, save the file as .vbs.
                Then to run the program, from the command prompt (Start->Run->cmd) simply type: cscript name.vbs
                You do no need internet however it would be handy for tutorials to learn from

                It doesnt matter how old your computer is as long as you have at least windows 95 (I think thats the minimum)

                As of your example above, in vbs you do not need to declare your variable (although it is best practise to always declare them :) )

                The above in vbs would look somthing like

                Code: [Select]
                DO
                Pass=""
                pass = InputBox("Please enter your password")
                Loop Until Pass="wood" or pass="name"