Solved

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

Posted on 2012-03-31
1
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

738 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