Removed recurisve
This commit is contained in:
parent
7822f074c4
commit
eb0f2299d3
12
MainForm.ps1
12
MainForm.ps1
@ -60,14 +60,6 @@ $btnConvert.Size = New-Object System.Drawing.Size(120, 30)
|
|||||||
$btnConvert.Text = "Convert to XLSX"
|
$btnConvert.Text = "Convert to XLSX"
|
||||||
$form.Controls.Add($btnConvert)
|
$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)
|
# Create Status TextBox (Top Right)
|
||||||
$txtStatus = New-Object System.Windows.Forms.TextBox
|
$txtStatus = New-Object System.Windows.Forms.TextBox
|
||||||
$txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
|
$txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
|
||||||
@ -121,8 +113,7 @@ $form.Controls.AddRange(@(
|
|||||||
$txtFolder,
|
$txtFolder,
|
||||||
$btnBrowse,
|
$btnBrowse,
|
||||||
$btnSaveConfig,
|
$btnSaveConfig,
|
||||||
$btnConnect,
|
$btnConnect
|
||||||
$chkRecursive # Add the checkbox to the form
|
|
||||||
))
|
))
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
@ -158,7 +149,6 @@ $btnBrowse.Add_Click({
|
|||||||
# Store the DataGridView and txtStatus in script scope
|
# Store the DataGridView and txtStatus in script scope
|
||||||
$script:dataGridView = $dataGridView
|
$script:dataGridView = $dataGridView
|
||||||
$script:txtStatus = $txtStatus
|
$script:txtStatus = $txtStatus
|
||||||
$script:chkRecursive = $chkRecursive
|
|
||||||
|
|
||||||
# Show form
|
# Show form
|
||||||
$form.Add_Shown({ $form.Activate() })
|
$form.Add_Shown({ $form.Activate() })
|
||||||
|
|||||||
@ -259,24 +259,12 @@ function List-XlsFiles {
|
|||||||
#$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id
|
#$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||||
|
|
||||||
# Call the recursive function to process files and subfolders
|
# Call the recursive function to process files and subfolders
|
||||||
if ($script:chkRecursive.Checked) {
|
$script:txtStatus.Text += "Listing files in current folder...`n"
|
||||||
$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
|
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$script:txtStatus.Text += "Searching in root folder`n"
|
$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
|
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($fileList.Count -gt 0) {
|
if ($fileList.Count -gt 0) {
|
||||||
$script:txtStatus.Text += "Saving file list...`n"
|
$script:txtStatus.Text += "Saving file list...`n"
|
||||||
@ -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 to get XLS files from only the current folder
|
||||||
function Get-XlsFilesCurrentFolder {
|
function Get-XlsFilesCurrentFolder {
|
||||||
param (
|
param (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user