Solved

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

Posted on 2012-03-31
1
411 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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