From eb0f2299d3226b2dcb6052aa080a35239e4161db Mon Sep 17 00:00:00 2001 From: Bobby Abellana Date: Mon, 24 Feb 2025 14:39:31 -0800 Subject: [PATCH] Removed recurisve --- MainForm.ps1 | 12 +------ SharePointFunctions.ps1 | 69 +++-------------------------------------- 2 files changed, 5 insertions(+), 76 deletions(-) diff --git a/MainForm.ps1 b/MainForm.ps1 index 554c49b..bc8e9f1 100644 --- a/MainForm.ps1 +++ b/MainForm.ps1 @@ -60,14 +60,6 @@ $btnConvert.Size = New-Object System.Drawing.Size(120, 30) $btnConvert.Text = "Convert to XLSX" $form.Controls.Add($btnConvert) -# Create Checkbox for Recursive Listing -$chkRecursive = New-Object System.Windows.Forms.CheckBox -$chkRecursive.Location = New-Object System.Drawing.Point(20, 205) -$chkRecursive.Size = New-Object System.Drawing.Size(150, 20) -$chkRecursive.Text = "List Recursively" -$chkRecursive.Checked = $true # Default to recursive -$form.Controls.Add($chkRecursive) - # Create Status TextBox (Top Right) $txtStatus = New-Object System.Windows.Forms.TextBox $txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner @@ -121,8 +113,7 @@ $form.Controls.AddRange(@( $txtFolder, $btnBrowse, $btnSaveConfig, - $btnConnect, - $chkRecursive # Add the checkbox to the form + $btnConnect )) # Load configuration @@ -158,7 +149,6 @@ $btnBrowse.Add_Click({ # Store the DataGridView and txtStatus in script scope $script:dataGridView = $dataGridView $script:txtStatus = $txtStatus -$script:chkRecursive = $chkRecursive # Show form $form.Add_Shown({ $form.Activate() }) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 41655a8..87f67a2 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -259,23 +259,11 @@ function List-XlsFiles { #$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id # Call the recursive function to process files and subfolders - if ($script:chkRecursive.Checked) { - $script:txtStatus.Text += "Listing files recursively...`n" - $fileList = Get-XlsFilesRecursive -DriveId $drive.Id -DriveItemId $folderItem.id - } else { - $script:txtStatus.Text += "Listing files in current folder only...`n" - $fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $folderItem.id - } + $script:txtStatus.Text += "Listing files in current folder...`n" + $fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $folderItem.id } else { - $script:txtStatus.Text += "Searching in root folder`n" - - if ($script:chkRecursive.Checked) { - $script:txtStatus.Text += "Listing files recursively...`n" - $fileList = Get-XlsFilesRecursive -DriveId $drive.Id -DriveItemId $root.Id - } else { - $script:txtStatus.Text += "Listing files in current folder only...`n" - $fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id - } + $script:txtStatus.Text += "Searching in root folder...`n" + $fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id } if ($fileList.Count -gt 0) { @@ -299,55 +287,6 @@ function List-XlsFiles { } } -# Recursive function to get XLS files from a folder and its subfolders -function Get-XlsFilesRecursive { - param ( - [string]$DriveId, - [string]$DriveItemId - ) - - $allFiles = @() - - # Check if DriveId or DriveItemId is null or empty - if ([string]::IsNullOrEmpty($DriveId)) { - $script:txtStatus.Text += "Error: DriveId is null or empty`n" - return $allFiles - } - if ([string]::IsNullOrEmpty($DriveItemId)) { - $script:txtStatus.Text += "Error: DriveItemId is null or empty`n" - return $allFiles - } - - # Get items in the current folder - try { - $items = Get-MgDriveItemChild -DriveId $DriveId -DriveItemId $DriveItemId -ErrorAction Stop - } - catch { - $script:txtStatus.Text += "Error getting items: $($_.Exception.Message)`n" - return $allFiles - } - - foreach ($item in $items) { - $script:txtStatus.Text += "Checking item: $($item.Name)`n" - - # If it's a folder, recurse into it - if ($item.Folder -and $item.Folder.ChildCount -ne $null) { # Check if it's a folder AND has children - $script:txtStatus.Text += "Found folder: $($item.Name), recursing...`n" - $allFiles += Get-XlsFilesRecursive -DriveId $DriveId -DriveItemId $item.Id - } - # If it's an Excel file, add it to the list - elseif ($item.Name -like "*.xls" -or $item.Name -like "*.xlsx" -or $item.Name -like "*.xlsm") { - $script:txtStatus.Text += "Found XLS file: $($item.Name)`n" - $allFiles += [PSCustomObject]@{ - OriginalPath = $item.WebUrl - OriginalFileName = $item.Name - } - } - } - - return $allFiles -} - # Function to get XLS files from only the current folder function Get-XlsFilesCurrentFolder { param (