wsh script to backup data (Archive )

Author Message
smehtarajeev

  • Total Posts : 7
  • Scores: 0
  • Reward points : 0
  • Joined: 4/11/2009
  • Status: offline
wsh script to backup data (Archive ) Wednesday, September 02, 2009 10:06 PM (permalink)
0
Hello All,
 
I have created a script that will archive data files from a source folder into  a destination folder based created with the system DATE and TIME
The advantage is that it can be used for Archive purpose
 
Enjoy All,,
 
Inputs to reduce the length of the code will be appreciated
 
And can someone help me on how to post scripts in the forum??
 
I think i have posted this in a thread.
 
---------------------------source--------------------------------------------
 
 
 
'-----------------------------------------------------------------------------------------------------------------------------------------------
' THIS UTILITY WILL CREATE A FOLDER BASED ON THE DATE AND THE TIME  AS RUNNING ON THE LOCAL SYSTEM AND MOVE THE FILES TO THIS NEW FOLDER CREATED
' THE UTILITY RUNS FROM A FOLDER XXX(C:\dir_util_resides)
' THE SOURCE FOLDER FOR THE FILES IS XXX(C:\source_dir_files_to_be_moved)  - HERE THE BACK UP FILES SHOULD BE PLACED
' THE DEST. FOLDER FOR THE FILES IS XXX(C:\dest_main_folder) - THE UTILITY WILL MOVE ALL FILES FROM THIS FOLDER WHENEVER THE UTILITY IS EXECUTED(REFER SCHEDULED TASK IN WINDOWS FOR THIS). IT WILL CREATE A FOLDER WITH THE LOCAL DATE AND THE TIME STAMP AND MOVE THE FILES FROM SOURCE FOLDER INTO THIS FOLDER. NO FILES WILL BE OVERWRITTEN AT ANY TIME.
' THE FOLLOWING FOLDERS SHOULD BE MANUALLY CREATED  1 ) C:\dir_util_resides  2) C:\source_dir_files_to_be_moved  3) C:\dest_main_folder (folders will be created within this folder)
' ASSITANCE POSSIBLE AT :
smehtarajeev@hotmail.com
'-----------------------------------------------------------------------------------------------------------------------------------------------
Dim fso,source_collection_folder,check_files_in_folder,list_of_files,files
Dim get_files_existing
Dim count
Dim temp_file_list,temp_file_list_store_path,move_file_list,temp_file
Dim dest_files_folder,sf,df

Dim date_types
strYear   = Right(DatePart("yyyy",Date), 4)
strmonth   = Right(100+DatePart("m",Date), 2)
strdate  = Right(100+DatePart("d",Date), 2)

str_date = strYear   & strmonth & strdate 
strhour = Hour(Time)
strmin = Minute(Time)
'strsec = second(Time)
str_time = strhour & strmin

str_folder_name = str_date & "_" & str_time
'MsgBox str_folder_name
source_collection_folder = "C:\source_dir_files_to_be_moved"
source_files_folder = "C:\source_dir_files_to_be_moved"
temp_file_list_store_path = "C:\dir_util_resides"
dest_files_folder = "C:\dest_main_folder"
temp_file = "C:\dir_util_resides\filelist.txt"

Set fso = CreateObject("scripting.filesystemobject")
'check if the folder to which the file has to be moved exists
If (fso.FolderExists(source_collection_folder)) Then
 'MsgBox "folder exists" & source_collection_folder & " " & folder_name & current_time

 ' check if there are any files in here
  Set files_in_folder = fso.GetFolder(source_collection_folder)
  Set list_of_files  = files_in_folder.Files
   count = 0
    For Each files In list_of_files
     file = files.Name
     count= count+1
    Next
   
   
    ' if there are files then move them to a new folder which has the name of the current date and time stamp
    If count>=1 Then
     'create a list of these files to process to be moved
      Set folder = fso.GetFolder(source_collection_folder)
      Set temp_file_list = fso.CreateTextFile(temp_file_list_store_path&"\filelist.txt",True)
      Set files = folder.Files
       For Each folderidx In files
        temp_file_list.writeline(folderidx.Name)
       Next
      temp_file_list.close
    
      'create the folder
      create_folder_path = dest_files_folder & "\" &  str_folder_name
      'MsgBox create_folder_path
      Set folder_create = fso.CreateFolder(create_folder_path)
    
      'open the text file (temp_file_list)and get the files list in order to be moved
      Set temp_file_list = fso.opentextfile(temp_file_list_store_path&"\filelist.txt",1)
     
      Do While Not temp_file_list.AtEndOfStream
     
        s = temp_file_list.ReadLine
       
     
        'wait for 2 seconds since the DIRECTORY takes time to create and hence gives error
        Set WshShell = WScript.CreateObject("WScript.Shell")
                   
        'set the source and destination paths to move the file
        sf = source_collection_folder & "\" & s
        df = dest_files_folder &"\"& str_folder_name & "\" & s
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set afile = fso.GetFile(sf)
        WScript.Sleep 3000
        afile.Move df
       
          
      Loop
      'close the temp file
      temp_file_list.Close
      'delete the temp_file_list
      Set folder = fso.GetFolder(temp_file_list_store_path)
       fso.deleteFile(temp_file)
     
     
    Else
      'there are no files so end this now and do nothing . the schedule task will keep on polling untill the next time interval
      'MsgBox " there are "& count & " files in here . There is nothing to MOVE"
     End if
End If
Set fso= Nothing

---------------------------------source-------------------------------------------------
 
 
thanks
rajiv
 
 
Welcome
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9