Windows XP Script

Discussion in 'OT Technology' started by Sexual Vanilla, Oct 16, 2007.

  1. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    While I am pretty decent at programming in a normal programming language, I, for one, have never programmed a script/batch file for Windows XP, therefore I do not know if this can even be done.

    Basically, I would like to be able to monitor the size (in bytes) of a folder in XP, and if the size reaches a certain limit, dump the contents to another location and clear the folder. Can this be done?
     
    Last edited: Oct 16, 2007
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Code:
    Option Explicit
    Dim objFileSystem, objTheFolder, folder, newfolder, foldersize
    
    folder="c:\batchdir\ts-x01"
    newfolder="c:\batchdir\test\"
    foldersize=100
    
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objTheFolder = objFileSystem.GetFolder(folder)
    
    if objTheFolder.size > foldersize then
         if not objFileSystem.FolderExists(newfolder) then objFileSystem.CreateFolder(newfolder)
         objFileSystem.MoveFile folder & "\*.*", newfolder
    end if
    
    set objTheFolder = nothing
    set objFileSystem = nothing
    
     
  3. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    Thanks for the response. However, it doesn't seem to work.
    Code:
    Option Explicit
    Dim objFileSystem, objTheFolder, folder, newfolder, foldersize
    
    folder="c:\test1\"
    newfolder="c:\test2\test\"
    foldersize=100
    
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    Set objTheFolder = objFileSystem.GetFolder(folder)
    
    if objTheFolder.size > foldersize then
         if not objFileSystem.FolderExists(newfolder) then objFileSystem.CreateFolder(newfolder)
         objFileSystem.MoveFile folder & "\*.*", newfolder
    end if
    
    set objTheFolder = nothing
    set objFileSystem = nothing
    I've created the two folders seen above, placed a small .gif image in the test1 folder and tried changing the foldersize variable to 1, but nothing happens when I run the script. Ideally, I'm assuming the script should remove the gif image (if the size of the folder is greater than 1) and place it in the test2 folder.
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    and in a msgbox objTheFolder.size after the set command
     
  5. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Oh and remove the trailing \ on the newfolder
     

Share This Page