Skip to content

Instantly share code, notes, and snippets.

View KKire's full-sized avatar

KKire

  • 🇲🇰 Macedonia
View GitHub Profile
@KKire
KKire / MoveFiles.ps1
Created January 8, 2025 17:43
Move all files to a target directory that is set to the first folder one layer after the root folder.
# Define the root directory
$rootDir = (Get-Location).Path
# Get all files in subdirectories
$files = Get-ChildItem -Path $rootDir -Recurse -File
foreach ($file in $files) {
# Determine the target directory (one layer after the root folder)
$relativePath = $file.DirectoryName.Substring($rootDir.Length).TrimStart("\")
$targetDir = Join-Path $rootDir ($relativePath.Split("\")[0])