Solved

VBS moving files and directoires.

Posted on 2015-01-21
3
97 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

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 25

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

617 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