Skip to content

Instantly share code, notes, and snippets.

@mrhammadasif
Last active May 2, 2024 13:10
Show Gist options
  • Save mrhammadasif/12f62e6492fcbdc36d6add706f447000 to your computer and use it in GitHub Desktop.
Save mrhammadasif/12f62e6492fcbdc36d6add706f447000 to your computer and use it in GitHub Desktop.
Powershell Script to Move all Recursive specified extensions files to Specific Folder

Usage Examples

pwsh ./MoveFile.ps1 json

This will move all json files, recursively from Current Folder and Move it to ../json/* folder

# define a count variable
$count = 0
# get first argument
$source = $args[0]
mkdir("../$source")
Get-ChildItem -Recurse -Filter "*.$source" | ForEach-Object {
# $json = Get-Content $_ -Raw | ConvertFrom-Json
# $json | ConvertTo-Json | Set-Content $_
Write-Host "Move to: ../$source/$($_.FullName | Split-Path -Leaf)"
$_.MoveTo("../$source/$($_.FullName | Split-Path -Leaf)")
$count++
}
Write-Host "Total: " $count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment