Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f829647

Browse files
side quest, fixed move child item handeling with filenames that contains spaces
1 parent e3cef1e commit f829647

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

‎Project_Move-ChildItemUp/Helpers/MidLogicHelper/Move-FolderContents.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ function Move-FolderContents {
9393
# ! Notice:
9494
# moving a file to a destination with a new filename renames the file
9595
# try to do error catching
96-
Move-Item -Path $sourceFilePath -Destination $destinationFilePath
97-
Write-Verbose "Moved file '$sourceFilePath' to new path '$destinationFilePath'."
96+
97+
# Move the file, ensuring paths with spaces are handled correctly
98+
try {
99+
Move-Item -LiteralPath "$sourceFilePath" -Destination "$destinationFilePath"
100+
Write-Verbose "Moved file '$sourceFilePath' to new path '$destinationFilePath'."
101+
}
102+
catch {
103+
Write-Warning "Failed to move file '$sourceFilePath' to '$destinationFilePath'. Error: $_"
104+
}
98105
}
99106
}
100107
}

‎Project_Move-ChildItemUp/Move-ChildItemUp.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ function Move-ChildItemUp {
55
Moves the contents of specified folders up one level and cleans up empty folders.
66
77
.DESCRIPTION
8-
The `Move-ChildItemUp` function takes one or more folder paths as input, validates
9-
them, and moves the contents of each folder up one level. After moving the contents,
8+
The `Move-ChildItemUp` function takes one or more folder paths as input, validates
9+
them, and moves the contents of each folder up one level. After moving the contents,
1010
it removes any empty folders left behind. This function also accepts pipeline input.
1111
1212
.PARAMETER folderPath
13-
Specifies the path(s) of the folder(s) whose contents need to be moved up one level.
13+
Specifies the path(s) of the folder(s) whose contents need to be moved up one level.
1414
This parameter accepts pipeline input.
1515
1616
.INPUTS
@@ -30,8 +30,8 @@ function Move-ChildItemUp {
3030
3131
.EXAMPLE
3232
Get-ChildItem ./ -Directory | Move-ChildItemUp
33-
A very typical and useful case. Moves the contents of all folders in the current
34-
working directory up one level.
33+
A very typical and useful case. Moves the contents of all folders in the current
34+
working directory up one level.
3535
3636
.NOTES
3737
This is the main function. User should call this function. An alias is recommended.
@@ -58,7 +58,7 @@ function Move-ChildItemUp {
5858
try {
5959
Write-Host "Program starts..." -ForegroundColor Cyan
6060

61-
# Step 1:
61+
# Step 1:
6262
# Validate input array only, not the path
6363
Confirm-FolderArray $folderPathsArray
6464

@@ -74,7 +74,7 @@ function Move-ChildItemUp {
7474
# Step 4: Clean up empty folder only
7575
# Remove-Item -Path $source -Recurse -Force
7676
Remove-EmptyFolder $folderObjArray
77-
77+
7878
Write-Host "Program complete." -ForegroundColor Green
7979
}
8080
catch {

‎README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ If you find these scripts useful or have ideas for improvements, feel free to [o
277277

278278
## Author
279279

280-
**Jialiang Chang** -- undergraduate student, currently self-learning PowerShell scripting.
280+
**Jialiang Chang** -- undergraduate student, currently self-learning PowerShell scripting.
281281
This repository serves as both a learning log and a collection of practical scripts for everyday automation tasks.
282282
Feel free to explore, adapt, and reuse anything that helps your workflow.
283283

284284
## License
285285

286-
This project is licensed under the [MIT License](LICENSE).
286+
This project is licensed under the [MIT License](LICENSE).
287287
You're free to use, modify, and share this code — just include attribution when you do.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /