From 8f35f927c175192f210a72a8861a88ac9bf4465e Mon Sep 17 00:00:00 2001 From: gribse Date: Thu, 31 Oct 2024 00:56:34 +0100 Subject: [PATCH] Refactor folder creation logic to add leading zeros to AVP folder numbers --- GestionVersion2.2.py => GestionVersion2.3.py | 1 + GestionVersionV1.0.ps1 | 71 -------------------- 2 files changed, 1 insertion(+), 71 deletions(-) rename GestionVersion2.2.py => GestionVersion2.3.py (99%) delete mode 100644 GestionVersionV1.0.ps1 diff --git a/GestionVersion2.2.py b/GestionVersion2.3.py similarity index 99% rename from GestionVersion2.2.py rename to GestionVersion2.3.py index daf302a..b1198cf 100644 --- a/GestionVersion2.2.py +++ b/GestionVersion2.3.py @@ -103,6 +103,7 @@ def createNewAVP(): pause_debug("Finding the latest folder") latest_number = max(int(f[3:]) for f in folders) new_number = latest_number + 1 + new_number = str(new_number).zfill(2) new_folder_name = f"AVP{str(new_number).zfill(2)}" pause_debug(f"New folder number determined: {new_number}") diff --git a/GestionVersionV1.0.ps1 b/GestionVersionV1.0.ps1 deleted file mode 100644 index 44df0e6..0000000 --- a/GestionVersionV1.0.ps1 +++ /dev/null @@ -1,71 +0,0 @@ - -# Define the source directory -$sourceDirectory = ".\AVP" - -# Check if the parent directory is named "Projets" -$parentDirectory = Split-Path -Path $sourceDirectory -Parent -if ((Split-Path -Path $parentDirectory -Leaf) -eq "Projets") { - # Prompt the user for the project name - $projectName = Read-Host "Enter the project name" - - # Get the current year and month - $currentYear = (Get-Date).Year - $currentMonth = (Get-Date).Month.ToString("D2") - - # Get all folders starting with the current year and month in the source directory - $pattern = "$currentYear $currentMonth*" - $folders = Get-ChildItem -Path $sourceDirectory -Directory | Where-Object { $_.Name -like $pattern } - - # Find the folder with the largest number after the year and month - if ($folders.Count -eq 0) { - $newNumber = 1 - } else { - $latestFolder = $folders | Sort-Object -Property { [int]($_.Name -replace "[^\d]") } | Select-Object -Last 1 - $latestNumber = [int]($latestFolder.Name -replace "[^\d]") - $newNumber = $latestNumber + 1 - } - - # Create the new folder name - $newFolderName = "$currentYear $currentMonth $newNumber $projectName" - - # Create the new folder - $newFolderPath = Join-Path -Path $sourceDirectory -ChildPath $newFolderName - Write-Host "Creating new folder: $newFolderName" - New-Item -ItemType Directory -Path $newFolderPath -ErrorAction SilentlyContinue - - # Copy the current script to the new folder - $currentScriptPath = $MyInvocation.MyCommand.Path - Copy-Item -Path $currentScriptPath -Destination $newFolderPath -ErrorAction SilentlyContinue - - # Create "AVP" and "Donnees" folders inside the new folder - New-Item -ItemType Directory -Path (Join-Path -Path $newFolderPath -ChildPath "AVP") -ErrorAction SilentlyContinue - New-Item -ItemType Directory -Path (Join-Path -Path $newFolderPath -ChildPath "Donnees") -ErrorAction SilentlyContinue - - -} else { - # Existing logic for creating AVP folders - Write-Host "Getting folders in $sourceDirectory" - $folders = Get-ChildItem -Path $sourceDirectory -Directory | Where-Object { $_.Name -like "AVP*" } - - if ($folders.Count -eq 0) { - Write-Host "No folders found. Creating first folder: AVP01" - New-Item -ItemType Directory -Path (Join-Path -Path $sourceDirectory -ChildPath "AVP01") -ErrorAction SilentlyContinue - return - } - - Write-Host "Finding the latest folder" - $latestFolder = $folders | Sort-Object -Property { [int]($_.Name -replace "[^\d]") } | Select-Object -Last 1 - - $latestNumber = [int]($latestFolder.Name -replace "[^\d]") - $newNumber = $latestNumber + 1 - $newFolderName = "AVP" + $newNumber.ToString().PadLeft(2, '0') - - Write-Host "`nFolders found:" - $folders | ForEach-Object { Write-Host $_.Name } - Write-Host "`nWould you like to create the next AVP "$newFolderName" ? Press any key to continue or CTRL+C to exit..." - $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") - - $newFolderPath = Join-Path -Path $sourceDirectory -ChildPath $newFolderName - Write-Host "Creating new folder: $newFolderName" - New-Item -ItemType Directory -Path $newFolderPath -ErrorAction SilentlyContinue -} \ No newline at end of file