Solved

batch to copy a known directory, search for destination(s) then add there

Posted on 2012-03-31
1
383 Views
Last Modified: 2012-04-01
Here is what I am trying to accomplish...

I want to copy a known directory %temp%\bquest\PU

search all drives for folders named "battle quest" then deposit the copied PU folder there.  

Thanks in advance!
0
Comment
Question by:icecom4
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 37793284
here's a powershell script which detect the drives in the machine (C:, D: etc), then runs through all file system of each drive and
looks for a folder named "battle quest".
then copy it entirely into %temp%\bquest\PU.


cls
$dir2copy = [environment]::GetEnvironmentVariable("temp","User") + "\bquest\PU"
$dir2find = "battle quest"

function Recurse([string]$path) {
	
  	$fc = new-object -com scripting.filesystemobject
  	$folder = $fc.getfolder($path)
	Write-Host $folder.Name
	
	if($folder.Name -eq $dir2find){
		return $folder.Path;
	}
  
  	foreach($i in $folder.subfolders) {
		$res = Recurse($i.path);
		if($res -ne $null){return $res;}
  	}
  
  return $null;
}



Get-WmiObject Win32_DiskPartition | 
ForEach-Object { 	
    $partition = $_ 
    $logicaldisk = $partition.psbase.GetRelated('Win32_LogicalDisk') 
    if ($logicaldisk -ne $null) { 
        $logicaldisk | foreach {
			$path = Recurse($_.Name)
						
			if($path -ne $null)
			{
				Copy-Item $dir2copy $path -recurse
			
				break;
			}
		}
    } 
} 

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RoboCopy to Changing External Drives 2 38
Need to learn promise API 2 43
Groovy:unable to resolve class error 2 68
VBA Shell can't Find Word document 11 75
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

20 Experts available now in Live!

Get 1:1 Help Now