Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBS moving files and directoires.

Posted on 2015-01-21
3
Medium Priority
?
101 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 25

Accepted Solution

by:
NVIT earned 2000 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 25

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

972 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