PDA

View Full Version : Search and Move Script (W2K)



thalam
11-02-2005, 01:47 PM
Hi there,

I am new to windows scripting and having some difficulty finding the right commands and concepts.

I am trying to write a script that will basically search a defined hard drive for a specific file, once it finds the file its going to move the entire dir (folder) into a specified location.

I have been looking for the search and move command in scripting for a few days, yet I haven't found it. Or I have found it and I just don't know it yet.

I got this code:

Dim fso
set fso=createobject("scripting.filesystemobject")
fso.MoveFolder "source", "destination"
set fso=nothing

it was in another post here. But I tried this, and it didn't work.

Can someone please help me. Thanks a lot!!<P ID="edit"><FONT class="small">Edited by thalam on 11/02/05 14:02.</FONT></P>

thalam
11-22-2005, 06:57 AM
I have finished the script, and it works fine on my system (WIN XP PRO), but this script is to run on a server that is running Windows 2003. It copies over 12 out of 22 or 9 out of 14. I can't wrap my head around why this is causing an issue. Is it because of the operating system? Below is the script I wrote:

dim fso
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile Where Extension = 'arc'")

For Each objFile in colFiles
If objFile.Extension = "arc" Then
If objFile.FileName = "archiver" then
directory = objFile.path 'Gives the full path
driveName=Left(objfile.name,2) 'Gives the name of the drive
objFile.Delete 'Delets the arc file
chrCount = len(directory) 'Counts total number of characters
fromDir = Left(directory,chrCount-1) 'Get's full path without \ at the end
folderStart = InStrRev(fromDir, "\") 'Goes back until it finds \
changeFolder = Left(directory,folderStart) 'From the left, string goes back until first \
folderName=mid(directory,folderStart+1,chrCount-folderStart-1) 'Name of actual folder

'Copies the folders to f:\temp
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("f:\temp\" & folderName)
FSO.CopyFolder driveName & fromDir, "f:\temp\" & folderName

'Changes the archived folder name at the source
Set obj2FSO = CreateObject("Scripting.FileSystemObject")
obj2FSO.MoveFolder driveName & fromDir , driveName & changeFolder & "_Arc_" & folderName
End If
End If
Next
wscript.quit

agemmell
11-22-2005, 09:30 AM
My my situation is much like the one above except that I need to find the file, rename it to the parent folder name, then move the new file to another location. It looks like this could be modified to do this.

Any special suggestions?

thalam
11-24-2005, 02:54 PM
yea, you'll just have to do some more string manipulation before the copy/move command. I don't fully understand what you wanted to do. But this code with minor modification should do the trick.