{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-other-file-management-9b16385c01a3","title":"Organize and Manage Files with Rule-Driven Plans","summary":"Reorganize, back up, compress, split, and merge files using rule-driven workflows with PowerShell and Python scripts, including safe previews, conflict handling, and verification manifests.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-other-file-management-9b16385c01a3","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-other-file-management-9b16385c01a3","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-other-file-management-9b16385c01a3.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-other-file-management-9b16385c01a3\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure PowerShell 5.1+ or 7+ and Python 3.8+ are installed before running scripts. Prepare a source directory and define include\/exclude patterns, target structure, and retention rules as needed. The first deliverable is a manifest or plan file showing intended actions before execution.","instructions":"---\nname: file-management\ndescription: Organize, back up, compress, split, and merge files\/folders using rule-driven plans; use when you need safe previews, conflict handling, and verification before executing file operations.\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n# File Management\n\n## When to Use\n\n- You need to **reorganize a directory** (move\/copy\/rename) based on include\/exclude patterns and a target folder structure.\n- You want a **repeatable backup workflow** (copy or archive) with optional retention rules and verification manifests.\n- You need to **compress** a folder or a set of files to reduce size or package deliverables.\n- You must **split very large files** into fixed-size parts for transfer\/storage limits (binary-safe).\n- You need to **merge previously split parts** back into the original file reliably (binary-safe).\n\n## Key Features\n\n- **Safety-first planning**: generate a preview\/manifest of intended actions before writing changes.\n- **Rule-driven scope control**: root path + include\/exclude patterns + thresholds + target structure (see `references\/rule-schema.md`).\n- **Conflict handling**: default to skip\/rename on collisions; overwrite only with explicit confirmation.\n- **Non-destructive defaults**: avoid deletion unless explicitly requested.\n- **Verification support**: compare counts\/sizes and optionally generate hashes for critical backups.\n- **Binary-safe split\/merge**: split by fixed size and merge parts without corrupting binary data (`scripts\/`).\n\n## Dependencies\n\n- PowerShell 5.1+ (Windows PowerShell) or PowerShell 7+\n  - Cmdlets used: `Get-ChildItem`, `Copy-Item`, `Move-Item`, `Compress-Archive`, `Get-FileHash`\n- Python 3.8+ (for split\/merge scripts)\n  - `scripts\/split_file.py`\n  - `scripts\/merge_parts.py`\n\n## Example Usage\n\n### 1) Organize files with a preview plan (PowerShell)\n\n```powershell\n# Inputs (adjust to your case)\n$Root = \"D:\\Inbox\"\n$Target = \"D:\\Organized\"\n$Include = @(\"*.pdf\",\"*.docx\")\n$ExcludeDirs = @(\"node_modules\",\".git\")\n$WhatIf = $true  # set to $false to execute\n\n# Build a manifest (preview plan)\n$files = Get-ChildItem -Path $Root -Recurse -File |\n  Where-Object {\n    ($Include | ForEach-Object { $_ }) -contains $_.Extension -eq $false\n  }\n\n# Practical include filter (simple example)\n$files = Get-ChildItem -Path $Root -Recurse -File -Include $Include\n\n# Exclude directories by path segment\n$files = $files | Where-Object {\n  $p = $_.FullName\n  -not ($ExcludeDirs | Where-Object { $p -match [regex]::Escape(\"\\$_\\\") })\n}\n\n$plan = foreach ($f in $files) {\n  # Example target structure: by extension\n  $ext = $f.Extension.TrimStart(\".\").ToLower()\n  $destDir = Join-Path $Target $ext\n  $destPath = Join-Path $destDir $f.Name\n\n  [pscustomobject]@{\n    Source = $f.FullName\n    Destination = $destPath\n    Action = \"Copy\"  # start with Copy; switch to Move after verification\n  }\n}\n\n# Preview\n$plan | Format-Table -AutoSize\n\n# Execute (safe defaults: create dirs; do not overwrite unless you decide to)\nforeach ($item in $plan) {\n  $destDir = Split-Path $item.Destination -Parent\n  if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir | Out-Null }\n\n  if (Test-Path $item.Destination) {\n    # Default conflict strategy: rename\n    $base = [IO.Path]::GetFileNameWithoutExtension($item.Destination)\n    $ext  = [IO.Path]::GetExtension($item.Destination)\n    $dir  = Split-Path $item.Destination -Parent\n    $item.Destination = Join-Path $dir (\"{0}_{1}{2}\" -f $base, (Get-Date -Format \"yyyyMMddHHmmss\"), $ext)\n  }\n\n  if ($item.Action -eq \"Copy\") {\n    Copy-Item -LiteralPath $item.Source -Destination $item.Destination -WhatIf:$WhatIf\n  } else {\n    Move-Item -LiteralPath $item.Source -Destination $item.Destination -WhatIf:$WhatIf\n  }\n}\n```\n\n### 2) Backup + hash manifest (PowerShell)\n\n```powershell\n$Source = \"D:\\Project\"\n$BackupRoot = \"E:\\Backups\"\n$Stamp = Get-Date -Format \"yyyyMMdd_HHmmss\"\n$BackupDir = Join-Path $BackupRoot (\"Project_{0}\" -f $Stamp)\n\n# Copy backup\nCopy-Item -Path $Source -Destination $BackupDir -Recurse\n\n# Create a hash manifest for verification\n$manifestPath = Join-Path $BackupDir \"hash-manifest.sha256.txt\"\nGet-ChildItem -Path $BackupDir -Recurse -File |\n  ForEach-Object {\n    $h = Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName\n    \"{0}  {1}\" -f $h.Hash, ($_.FullName.Substring($BackupDir.Length + 1))\n  } | Set-Content -Encoding UTF8 $manifestPath\n```\n\n### 3) Compress a folder (PowerShell)\n\n```powershell\n$SourceDir = \"D:\\Project\"\n$ZipPath = \"E:\\Archives\\Project.zip\"\n\nCompress-Archive -Path (Join-Path $SourceDir \"*\") -DestinationPath $ZipPath -Force\n```\n\n### 4) Split and merge a large file (Python)\n\n```bash\n# Split into 100MB parts (binary-safe)\npython scripts\/split_file.py --input \"E:\\ISO\\big.iso\" --part-size 100MB --output-dir \"E:\\ISO\\parts\"\n\n# Merge parts back (binary-safe)\npython scripts\/merge_parts.py --input-dir \"E:\\ISO\\parts\" --output \"E:\\ISO\\big.iso\"\n```\n\n> Note: CLI flags may vary depending on the scripts\u2019 implementation. If the scripts do not expose flags, adapt the commands to match their actual parameters.\n\n## Implementation Details\n\n- **Rule schema and planning**\n  - Prefer structured rules to define:\n    - `rootPath`\n    - include\/exclude patterns (glob-like)\n    - optional size thresholds (e.g., split if `> N MB`)\n    - target structure mapping (e.g., by extension\/date\/project)\n    - conflict strategy (`skip`, `rename`, `overwrite`)\n  - Use `references\/rule-schema.md` as the canonical format for describing these rules.\n\n- **Preview-first execution**\n  - Generate a **manifest\/plan** listing `(source, destination, action)` before any write operation.\n  - Use PowerShell `-WhatIf` (or an explicit \u201cdry run\u201d mode) to validate the plan.\n\n- **Conflict handling**\n  - Default behavior should be **non-destructive**:\n    - If destination exists: **rename** (append timestamp or counter) or **skip**\n    - Only **overwrite** after explicit user confirmation\n\n- **Verification**\n  - Basic checks: file counts and total sizes before\/after.\n  - Strong checks for critical backups: `SHA256` via `Get-FileHash`, stored as a manifest for later validation.\n\n- **Binary-safe splitting\/merging**\n  - Splitting should read\/write raw bytes in fixed-size chunks (no text encoding).\n  - Merging should concatenate parts in deterministic order (e.g., numeric suffix ordering) to reproduce the original byte stream exactly.","use_cases":["Reorganize a directory based on include\/exclude patterns and target structure","Create a repeatable backup workflow with verification manifests","Compress a folder or set of files to reduce size or package deliverables","Split large files into fixed-size parts for transfer\/storage","Merge previously split parts back into the original file"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Other\/file-management\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-26","created_at":"2026-11-24T14:52:59.000000Z","updated_at":"2026-11-26T09:25:02.000000Z","seo_title":"Organize Files with Rule-Driven Plans","seo_description":"Use PowerShell and Python scripts to organize, back up, compress, split, and merge files with safe previews and conflict handling.","seo_keywords":["organize files with rules","backup files with PowerShell","compress folders with script","split large files","merge file parts"]}}