projects:windows
Различия
Показаны различия между двумя версиями страницы.
| Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия | ||
| projects:windows [2025/03/23 23:57] – | projects:windows [2025/11/14 11:22] (текущий) – | ||
|---|---|---|---|
| Строка 1: | Строка 1: | ||
| ====== Проекты для Windows ====== | ====== Проекты для Windows ====== | ||
| + | // | ||
| - | ===== PowerShell скрипт для сортировки по расширениям ====== | + | [[windows:scripts|Windows |
| - | + | ||
| - | Скрипт в качестве аргумента может принимать пусть к каталогу\\ | + | |
| - | Если в каталоге со скриптом нет файла с конфигурацией | + | |
| - | '' | + | |
| - | + | ||
| - | <code powershell> | + | |
| - | $configPath = " | + | |
| - | + | ||
| - | # Функция загрузки конфигурации из INI с поддержкой игнорирования файлов | + | |
| - | function Load-Config { | + | |
| - | param ($configPath) | + | |
| - | + | ||
| - | if (!(Test-Path $configPath)) { | + | |
| - | @" | + | |
| - | [Extensions] | + | |
| - | Images = .jpg, .jpeg, .png, .gif, .bmp, .tiff, .webp, .ico, .psd | + | |
| - | Documents = .pdf, .doc, .docx, .txt, .xls, .xlsx, .ppt, .pptx, .rtf, .csv | + | |
| - | Archives = .zip, .rar, .7z, .tar, .gz, .bz2, .xz, .iso | + | |
| - | Videos = .mp4, .mkv, .avi, .mov, .wmv, .flv, .webm | + | |
| - | Music = .mp3, .wav, .flac, .aac, .ogg, .m4a, .wma | + | |
| - | Torrents = .torrent | + | |
| - | Software = .exe, .msi, .iso, .img, .bin, .dmg | + | |
| - | Code = .py, .js, .html, .css, .php, .java, .c, .cpp, .cs, .go, .rb, .ts, .sh, .bat, .ps1 | + | |
| - | 3DModels = .obj, .fbx, .stl, .blend, .3ds, .dae, .gltf | + | |
| - | VectorGraphics = .svg, .ai, .eps, .cdr | + | |
| - | Notes = .md, .rst | + | |
| - | System = .ini, .cfg, .reg, .log, .cmd | + | |
| - | Books = .epub, .mobi, .djvu | + | |
| - | Other = | + | |
| - | + | ||
| - | [Logging] | + | |
| - | EnableLogging = false | + | |
| - | LogFilePath = SortFiles.log | + | |
| - | + | ||
| - | [IgnoreFiles] | + | |
| - | Files = folder.ico, desktop.ini | + | |
| - | "@ | Out-File -Encoding UTF8 $configPath | + | |
| - | } | + | |
| - | + | ||
| - | $config = @{Extensions=@{}; | + | |
| - | $currentSection = "" | + | |
| - | foreach ($line in Get-Content $configPath) { | + | |
| - | $line = $line.Trim() | + | |
| - | if ($line -match " | + | |
| - | $currentSection = $matches[1] | + | |
| - | } elseif ($line -match " | + | |
| - | $key, $value = $matches[1, | + | |
| - | if ($currentSection -eq " | + | |
| - | $config.Extensions[$key] = $value -split ", | + | |
| - | } elseif ($currentSection -eq " | + | |
| - | $config.Logging[$key] = $value | + | |
| - | } elseif ($currentSection -eq " | + | |
| - | $config.IgnoreFiles = $value -split ", | + | |
| - | } | + | |
| - | } | + | |
| - | } | + | |
| - | return $config | + | |
| - | } | + | |
| - | + | ||
| - | $config = Load-Config $configPath | + | |
| - | $fileCategories = $config.Extensions | + | |
| - | $ignoredFiles = @($config.IgnoreFiles) | + | |
| - | if (!$ignoredFiles) { $ignoredFiles = @() } | + | |
| - | + | ||
| - | $enableLogging = $false | + | |
| - | if ($config.Logging[" | + | |
| - | $enableLogging = $true | + | |
| - | } | + | |
| - | $logFilePath = $config.Logging[" | + | |
| - | + | ||
| - | function Write-Log { | + | |
| - | param ($message) | + | |
| - | if ($enableLogging -and $logFilePath) { | + | |
| - | $timestamp = Get-Date -Format " | + | |
| - | " | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | # Определяем папку для сортировки с подтверждением | + | |
| - | if ($args.Count -gt 0 -and (Test-Path -PathType Container $args[0])) { | + | |
| - | $TargetFolder = $args[0] | + | |
| - | Add-Type -AssemblyName System.Windows.Forms | + | |
| - | $confirmation = [System.Windows.Forms.MessageBox]:: | + | |
| - | if ($confirmation -ne [System.Windows.Forms.DialogResult]:: | + | |
| - | Write-Host " | + | |
| - | exit | + | |
| - | } | + | |
| - | } else { | + | |
| - | Add-Type -AssemblyName System.Windows.Forms | + | |
| - | $folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog | + | |
| - | $folderBrowser.Description = "Выберите папку для | + | |
| - | if ($folderBrowser.ShowDialog() -eq " | + | |
| - | $confirmation = [System.Windows.Forms.MessageBox]:: | + | |
| - | if ($confirmation -ne [System.Windows.Forms.DialogResult]:: | + | |
| - | Write-Host "Операция отменена пользователем." | + | |
| - | exit | + | |
| - | } | + | |
| - | $TargetFolder = $folderBrowser.SelectedPath | + | |
| - | } else { | + | |
| - | Write-Host " | + | |
| - | exit | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | Write-Host "Выбранная папка: $TargetFolder" | + | |
| - | Write-Log " | + | |
| - | + | ||
| - | # Функция сортировки файлов с правильной нумерацией дубликатов | + | |
| - | function Sort-Files { | + | |
| - | param ($TargetFolder, | + | |
| - | + | ||
| - | Get-ChildItem -Path $TargetFolder -File | ForEach-Object { | + | |
| - | if ($ignoredFiles -contains $_.Name) { | + | |
| - | Write-Log " | + | |
| - | return | + | |
| - | } | + | |
| - | + | ||
| - | $file = $_ | + | |
| - | $destination = $fileCategories.Keys | Where-Object { $file.Extension -in $fileCategories[$_] } | Select-Object -First 1 | + | |
| - | if (-not $destination) { $destination = " | + | |
| - | + | ||
| - | $destPath = Join-Path $TargetFolder $destination | + | |
| - | if (!(Test-Path $destPath)) { New-Item -Path $destPath -ItemType Directory | Out-Null } | + | |
| - | + | ||
| - | $baseName = $file.BaseName -replace " \(Copy \d+\)$", | + | |
| - | $extension = $file.Extension | + | |
| - | $newPath = Join-Path $destPath " | + | |
| - | $counter = 1 | + | |
| - | + | ||
| - | while (Test-Path $newPath) { | + | |
| - | $newPath = Join-Path $destPath " | + | |
| - | $counter++ | + | |
| - | } | + | |
| - | + | ||
| - | try { | + | |
| - | Move-Item -Path $file.FullName -Destination $newPath -ErrorAction Stop | + | |
| - | Write-Log " | + | |
| - | } | + | |
| - | catch { | + | |
| - | Write-Log " | + | |
| - | } | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | Sort-Files -TargetFolder $TargetFolder -fileCategories $fileCategories -ignoredFiles $ignoredFiles | + | |
| - | + | ||
| - | </ | + | |
| ---- | ---- | ||
projects/windows.1742763452.txt.gz · Последнее изменение: —
