Navigate folders and subfolders with powershell

1

Recently I did a recovery of the data of a HD, but the folder where the files are, is separated by subfolders with the name of each extension (eg, jpg, gif ...), and each subfolder contains other subfolders separating the files in "small" quantities (eg png [11001-12000]).

I wanted to mount a script in powershell so I could copy only files larger than 100 KB, for example, to another folder. Doing some research, I found a script that does something similar

foreach($file in (Get-Item C:\Users\MEU_USUÁRIO\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*))
{
    if ((Get-Item $file).length -lt 100kb) { continue }
    Copy-Item $file.FullName "C:\Users\MEU_USUÁRIO\Pictures\PASTA_QUALQUER\$($file.Name).jpg";
}

It copies those images from windows spotlight to be able to put them in the background, but it does not come close to what you need just for not navigating the subfolders and such. I have no knowledge of powershell, and I need your help to solve this little problem, and it's a bit of a break to learn.

    
asked by anonymous 17.06.2017 / 17:22

1 answer

0

After researching and studying a bit, I wrote the following code:

foreach($arq in (Get-ChildItem "DIRETORIO_DE_ORIGEM" -Recurse -Include "*.png", "*.gif", "*.bmp", "*.tif", "*.jpg"))
{
    if ((Get-Item $arq).Length -ge 200kb) {Copy-Item $arq.Fullname "DIRETORIO_DE_DESTINO\$($arq.Name)"}    
}

It copies the files from the DIRECTORY_TO_ORIGEM greater than or equal to 200kb to the DIRECTORY_DESTINATION. What I had to change was the name of folders that used characters that were not allowed (eg from "png [something]]" to "png", or " png (some_ thing) ", for example)

You can use the Move-Item cmdlet instead of Copy-Item , to "trim" the file.

    
21.06.2017 / 20:22