Solved

VBS moving files and directoires.

Posted on 2015-01-21
3
90 Views
Last Modified: 2015-01-21
I have several different machines that use Flash drives for logs  no network connection.   Each month I want to move the logs to a network drive.

I would like the vbs to run on the flash drive when selected.
The Flash drive is typically the f: drive but that could change if another flash drive is in the user’s desktop.

The Flash drive has two directories on it
PathosDelta_093904020
PathosDelta_094305024

I want to move all Subdirectories to
L:\Pathos\PathosDelta_093904020-Pathos_1
L:\Pathos\PathosDelta_094305024-PATHOS_2

PathosDelta_093904020  all subdirectories and files moved to   L:\Pathos\PathosDelta_093904020-Pathos_1

PathosDelta_094305024  all subdirectories and files moved to    L:\Pathos\PathosDelta_094305024-PATHOS_2

If a directory and or file exist in the move to directory it should be overwritten.  


I have tried and now I am frustrated…
0
Comment
Question by:JaysonJackson
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40562894
MovDir.vbs
On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
cSrcFolder="F:\PathosDelta_094305024"
cTgtFolder="L:\Pathos\PathosDelta_094305024-PATHOS_2"
If objFSO.FolderExists(cSrcFolder) Then
  call DoIt
Else
  WScript.Echo "Missing source folder " & cSrcFolder
End If
  

Function DoIt()
  On Error Resume Next
  If objFSO.FolderExists(cTgtFolder) Then
    WScript.Echo "Deleting target " & cTgtFolder
    objFSO.DeleteFolder(cTgtFolder)
    If Err.Number <> 0 Then
      WScript.Echo "Error during delete " & cTgtFolder & " " & Err.Description
      Err.Clear
    End If
  End If
  call CopyFolder
End Function

Function CopyFolder()
  On Error Resume Next
  If objFSO.FolderExists(cSrcFolder) Then
    WScript.Echo "Copying... "
    objFSO.CopyFolder cSrcFolder , cTgtFolder , OverWriteFiles
    If Err.Number <> 0 Then
      WScript.Echo "Error during copy " & cSrcFolder & " " & cTgtFolder  & Err.Description
      Err.Clear
    End If
  End If
End Function

Open in new window

0
 

Author Closing Comment

by:JaysonJackson
ID: 40562909
Awesome.   thanks again for solving my Headache
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40562917
You're welcome, JaysonJackson. I'm glad it helps.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question