Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Create, Move and Ignore Folders+Contents

  • Filter
  • Time
  • Show
Clear All
new posts

  • Create, Move and Ignore Folders+Contents

    Just wondering if anyone has any thoughts on this before I start...

    I fairly often have to create a folder (archive), then move the contents of all the folders apart from a few specific ones into the archive folder.

    So, for example;

    C:\_Temp_\ has 10 folders within;

    I want to create a folder ' C:\_Temp_\Archive_date\' and move all the 10 folders apart from a couple of them 'Admin' and 'Default' into the archive folder.

    I'd then be left with c:\_Temp_\Archive_date\ , C:\_Temp_\Admin and C:\Temp\Default - with Archive_date filled with all the previous folders ready for deleting later

    if it helps the idea of the thing was;
    *Create log file on local machine
    *create archive folder on remote machine (archive date')
    *EXCLUDE 'admin'/'local file' and 'archive date' folders; but copy entire contents (folders) into archive date folder.
    log the folders moved into the log file...
    Last edited by Lan; 15th August 2007, 16:04. Reason: adding _
    This is my signature.

  • #2
    Re: Create, Move and Ignore Folders+Contents

    Creates a log file, creates archive folder with the date and moves a folder...

    What I need it to do is write to the log file what its doing - i.e. 'creating folder' and 'moving folder names'

    also to then gather all the folders in that location and then somehow tell it to miss Admin and Local folders completely and move the rest...

    ' Variables
    strComputer = InputBox("Enter Computer Name:", "Folder Cleanup", "?")
    If NOT Left(strComputer,2) = "\\" Then
        strComputer = "\\" & strComputer
    End If
    Path = strComputer & "\c$\_Temp_" 
    ' Subfolders to be processed - True/False
    Subfolders = True
    ' Create a log file for this
    ' * Change the path to where the log file is.
    ' * Be sure the text file already exists or else 
    ' * script will fail.
    strLogFile = "c:\logs\" & Right(strComputer, Len(strComputer) - 2) & "_fileArchiveLog.txt"
    ' Log file creation/check
    strDirectory = "c:\logs"
    strFile = "\" & Right(strComputer, Len(strComputer) - 2) & "_fileArchiveLog.txt"
    ' Create the File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ' Check that the strDirectory folder exists
    If objFSO.FolderExists(strDirectory) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
    Set objFolder = objFSO.CreateFolder(strDirectory)
    End If
    If objFSO.FileExists(strDirectory & strFile) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
    Wscript.Echo "Created " & strDirectory & strFile
    End If 
    set objFolder = nothing
    set objFile = nothing
    If err.number = vbEmpty then
    Set objShell = CreateObject("WScript.Shell")
    ' Open's Log File Directory ("Explorer" & " " & strDirectory & "\" )
    Else WScript.echo "VBScript Error: " & err.number
    End If
    ' *******************************************************
    ' Create Archive Folder and Move Folders Start
    ' *******************************************************
    ' Create Archive Folder
    dim filesys, ArchFol, ArchPath
    ArchPath = strComputer & "\c$\_test_\_Archive_" & FormatDateTime(date(),vblongdate)
    set filesys=CreateObject("Scripting.FileSystemObject")
    If Not filesys.FolderExists(ArchPath) Then
    Set ArchFol = filesys.CreateFolder(ArchPath)
    End If
    dim Movesys
    set Movesys = CreateObject("Scripting.FileSystemObject")
    If Movesys.FolderExists(strComputer & "\c$\_test_\Folder (1)") Then
       Movesys.MoveFolder strComputer & "\c$\_test_\Folder (1)", strComputer & "\c$\_test_\_Archive_" & FormatDateTime(date(),vblongdate) & "\"
    End If
    This is my signature.