Solved

Moving files script

Posted on 2007-03-19
8
463 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:habsboys
Comment Utility
Hi

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

Andrew
0
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

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
My mistake...change it to this:

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

Author Comment

by:habsboys
Comment Utility
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
Comment Utility
strExt=objFSO.GetExtensionName
should have read

strExt=objFSO.GetExtensionName(file.name)
0
 

Author Comment

by:habsboys
Comment Utility
Cheers

Worked like a dream.

Thanks for your help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

12 Experts available now in Live!

Get 1:1 Help Now