Solved

Moving files script

Posted on 2007-03-19
8
465 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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