>

Catatan kode membuat folder otomatis


# 1    Lokasi utama baru membuat folder 
$basePath = "E:\PROJECT COMIC DEWI\Tale of a Scribe Who Retires to the Countryside"

# Loop sebanyak 47 kali untuk membuat Folder1 sampai Folder47
for ($i = 1; $i -le 47; $i++) {
    # Buat path untuk folder utama
    $mainFolder = Join-Path $basePath "Folder$i"

    # Buat folder utama
    New-Item -ItemType Directory -Path $mainFolder -Force

    # Buat subfolder 'hasil'
    New-Item -ItemType Directory -Path (Join-Path $mainFolder "hasil") -Force

    # Buat subfolder 'merge'
    New-Item -ItemType Directory -Path (Join-Path $mainFolder "merge") -Force

    Write-Host "Folder$i sudah dibuat"
}

# 2    Lokasi utama project memindahkan 5 chapter
$basePath = "E:\PROJECT COMIC DEWI\Tale of a Scribe Who Retires to the Countryside"

# Ambil semua folder chapter, urutkan berdasarkan angka di nama
$chapters = Get-ChildItem -Path $basePath -Directory | Where-Object { $_.Name -like "Chapter*" } |
    Sort-Object { 
        # Ambil angka dari nama folder, misalnya "Chapter_110" -> 110
        [int]($_.Name -replace '\D+', '')
    }

# Index awal
$chapterIndex = 0

# Hitung jumlah folder yang dibutuhkan (235 ÷ 5 = 47)
$folderCount = [math]::Ceiling($chapters.Count / 5)

for ($i = 1; $i -le $folderCount; $i++) {
    $hasilFolder = Join-Path $basePath "Folder$i\hasil"

    # Ambil 5 chapter untuk folder ini
    $group = $chapters[$chapterIndex..([math]::Min($chapterIndex+4, $chapters.Count-1))]

    foreach ($ch in $group) {
        $destPath = Join-Path $hasilFolder $ch.Name
        Move-Item -Path $ch.FullName -Destination $destPath -Force
    }

    $chapterIndex += 5
    Write-Host "Folder$i selesai -> Chapter masuk: $($group.Name -join ', ')"
}

# 3    Lokasi utama merge menyatukan
$basePath = "E:\PROJECT COMIC DEWI\Tale of a Scribe Who Retires to the Countryside"

# Loop semua Folder
for ($i = 1; $i -le 47; $i++) {
    $hasilFolder = Join-Path $basePath "Folder$i\hasil"
    $mergeFolder = Join-Path $basePath "Folder$i\merge"

    # Bersihkan isi merge
    Get-ChildItem -Path $mergeFolder -Recurse -Force | Remove-Item -Recurse -Force

    $counter = 1

    # Ambil semua file gambar dari hasil
    $files = Get-ChildItem -Path $hasilFolder -Recurse -File -Include *.jpg, *.png | Sort-Object Name

    foreach ($file in $files) {
        $ext = $file.Extension
        $newName = "{0:D3}{1}" -f $counter, $ext
        $destPath = Join-Path $mergeFolder $newName
        Copy-Item -Path $file.FullName -Destination $destPath -Force
        $counter++
    }

    Write-Host "Folder$i selesai -> Total file:" ($counter - 1)
}


Merge berdasarkan numerik
$destination = "E:\PROJECT COMIC DEWI\memorize\Folder20\merge"

# Bersihkan folder hasil
if (Test-Path $destination) {
    Remove-Item "$destination\*" -Force
}
else {
    New-Item -ItemType Directory -Path $destination
}

$counter = 1

$folders = Get-ChildItem -Directory |
    Where-Object { $_.Name -like "Chapter_*" } |
    Sort-Object { [int]($_.Name -replace 'Chapter_','') }

foreach ($folder in $folders) {
    Write-Host "Processing $($folder.Name)"

    $files = Get-ChildItem $folder.FullName -File |
             Sort-Object { [int]($_.BaseName) }

    foreach ($file in $files) {
        $ext = $file.Extension
        $newName = "{0:D3}{1}" -f $counter, $ext
        Copy-Item $file.FullName "$destination\$newName"
        Write-Host "Copied -> $newName"
        $counter++
    }
}

Write-Host ""
Write-Host "Selesai!"
Write-Host "Total file:" ($counter - 1)
pause

0 Response to "Catatan kode membuat folder otomatis"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel