Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBS moving files and directoires.

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
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

721 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