Solved

Moving files script

Posted on 2007-03-19
8
466 Views
Last Modified: 2008-01-09
Hi i would like to create a vbs script or a batch file that can be deployed using a gpo for computers.
I would like to move files from C:\Gallery Data Files\ to C:\Program Files\SMART Board Software\Gallery.
The only file extentions i want to move are .galleryitem, .notebook and xml files. i have written a basic batch file but it does not execute via a GPo but does when you are it manaully,
the batch file i have is below and it is deployed via a gpo using a computer startup.
cd\
move /y "C:\Gallery Data Files\*.galleryitem" "C:\Program Files\SMART Board Software\Gallery"
move /y "C:\Gallery Data Files\*.notebook" "C:\Program Files\SMART Board Software\Gallery"
move /y "C:\Gallery Data Files\*.xml" "C:\Program Files\SMART Board Software\Gallery"

hope u can help

Andrew
0
Comment
Question by:habsboys
  • 4
  • 4
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18748939
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder=objFSO.GetFolder("C:\Gallery Data Files\")

For each file in objFolder.Files
  strExt=objFSO.GetExtensionName
  If strExt="galleryitem" or strExt= "notebook" or strExt="xml" Then
    objFSO.Move file.path, "C:\Program Files\SMART Board Software\Gallery\"
  End If
Next


Or you can simply use
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\Gallery Data Files\*.galleryitem" , "C:\Program Files\SMART Board Software\Gallery\"
objFSO.MoveFile "C:\Gallery Data Files\*.notebook" , "C:\Program Files\SMART Board Software\Gallery\"
objFSO.MoveFile "C:\Gallery Data Files\*.xml" , "C:\Program Files\SMART Board Software\Gallery\"
0
 

Author Comment

by:habsboys
ID: 18754906
Thanks for that

it works however there is an error when  an identical file exists in the destination folder or if the there is no files to move.

I would like it to move the files and overwrite the destination ones without been prompted and if there are no files to move just close with no error.

Andrew
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18755380
Try this...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder=objFSO.GetFolder("C:\Gallery Data Files\")
strTarget="C:\Program Files\SMART Board Software\Gallery\"
For each file in objFolder.Files
  strExt=objFSO.GetExtensionName
  If strExt="galleryitem" or strExt= "notebook" or strExt="xml" Then
    If objFSO.FileExists (strTarget & file.name) Then
      objFSO.CopyFile file.path, strTarget, True
      objFSO.DeleteFile file.path
    Else
      objFSO.Move file.path, strTarget
    End If
  End If
Next
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:habsboys
ID: 18755744
Hi

I get the following error:
Script:......
line: 2
Char: 14
Error: Expected end of statement
Code: 800A0401

Andrew
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18755754
My mistake...change it to this:

Dim objFolder:Set objFolder=objFSO.GetFolder("C:\Gallery Data Files\")
0
 

Author Comment

by:habsboys
ID: 18755805
I get another error

Line : 5
Char:3
Error: wronh number of arguments or invalid property assigngment "GetExtensionName!

Andrew
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18755862
strExt=objFSO.GetExtensionName
should have read

strExt=objFSO.GetExtensionName(file.name)
0
 

Author Comment

by:habsboys
ID: 18755937
Cheers

Worked like a dream.

Thanks for your help
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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