Forum Discussion
_OSD_
Nov 26, 2020Copper Contributor
PowerShell to find and copy a file with wildcard
Hi, I need to copy a file which is located under a dynamically created subdirectory. Directory: C:\Users\StandardUser\AppData\Roaming\Mozilla\Firefox\Profiles\dynamically-created-directory\myDesire...
NZScottie
Dec 12, 2020Copper Contributor
_OSD_ I would try something like the code below, assuming there are multiple profile directories and you want to replicate that in the destination directory.
$SourceDir = 'C:\Users\StandardUser\AppData\Roaming\Mozilla\Firefox\Profiles'
$DestinationDir = 'C:\FireFox\'
$FileNameAndExtension = 'places.sqlite'
$SQLiteFiles = Get-ChildItem -Path "$SourceDir*\$FileNameAndExtension"
foreach($SQLiteFile in $SQLiteFiles){
$ParentFolder = $SQLiteFile.Directory -replace [regex]::Escape("$SourceDir")
New-Item -ItemType Directory -Name "$DestinationDir$ParentFolder"
Copy-Item -Path $SQLiteFile -Destination "$DestinationDir$ParentFolder"
}
Hopefullly I have understood what you were after. 😉