Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

22 Experts available now in Live!

Get 1:1 Help Now