Solved

VBS moving files and directoires.

Posted on 2015-01-21
3
85 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 23

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 23

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now