?
Solved

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

Posted on 2012-03-31
1
Medium Priority
?
430 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 2000 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

Independent Software Vendors: 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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

801 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