GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make Move-Item work with its -Include, -Exclude, and -Filter paramete… · PowerShell/PowerShell@5ee4ec1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/Microsoft.PowerShell.Commands.Management/commands/management
    • Navigation.cs
  • test/powershell/Modules/Microsoft.PowerShell.Management
    • Move-Item.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs‎

Copy file name to clipboardExpand all lines: src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3510,7 +3510,7 @@ private Collection<PathInfo> GetResolvedPaths(string path)
35103510
Collection<PathInfo> results = new Collection<PathInfo>();
35113511
try
35123512
{
3513-
results = SessionState.Path.GetResolvedPSPathFromPSPath(path);
3513+
results = SessionState.Path.GetResolvedPSPathFromPSPath(path, CmdletProviderContext);
35143514
}
35153515
catch (PSNotSupportedException notSupported)
35163516
{
Collapse file

‎test/powershell/Modules/Microsoft.PowerShell.Management/Move-Item.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Modules/Microsoft.PowerShell.Management/Move-Item.Tests.ps1
+87Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,91 @@ Describe "Move-Item tests" -Tag "CI" {
1111
test-path $target | Should be $true
1212
"$target" | Should ContainExactly "This is content"
1313
}
14+
15+
Context "Move-Item with filters" {
16+
BeforeAll {
17+
$filterPath = "$TESTDRIVE/filterTests"
18+
$moveToPath = "$TESTDRIVE/dest-dir"
19+
$renameToPath = Join-Path $filterPath "move.txt"
20+
$filePath = Join-Path $filterPath "*"
21+
$fooFile = "foo.txt"
22+
$barFile = "bar.txt"
23+
$booFile = "boo.txt"
24+
$fooPath = Join-Path $filterPath $fooFile
25+
$barPath = Join-Path $filterPath $barFile
26+
$booPath = Join-Path $filterPath $booFile
27+
$newFooPath = Join-Path $moveToPath $fooFile
28+
$newBarPath = Join-Path $moveToPath $barFile
29+
$newBooPath = Join-Path $moveToPath $booFile
30+
$fooContent = "foo content"
31+
$barContent = "bar content"
32+
$booContent = "boo content"
33+
}
34+
BeforeEach {
35+
New-Item -ItemType Directory -Path $filterPath | Out-Null
36+
New-Item -ItemType Directory -Path $moveToPath | Out-Null
37+
New-Item -ItemType File -Path $fooPath -Value $fooContent | Out-Null
38+
New-Item -ItemType File -Path $barPath -Value $barContent | Out-Null
39+
New-Item -ItemType File -Path $booPath -Value $booContent | Out-Null
40+
}
41+
AfterEach {
42+
Remove-Item $filterPath -Recurse -Force -ErrorAction SilentlyContinue
43+
Remove-Item $moveToPath -Recurse -Force -ErrorAction SilentlyContinue
44+
}
45+
It "Can move to different directory, filtered with -Include" {
46+
Move-Item -Path $filePath -Destination $moveToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue
47+
$e | Should BeNullOrEmpty
48+
$barPath | Should Not Exist
49+
$newBarPath | Should Exist
50+
$booPath | Should Exist
51+
$fooPath | Should Exist
52+
$newBarPath | Should ContainExactly $barContent
53+
}
54+
It "Can move to different directory, filtered with -Exclude" {
55+
Move-Item -Path $filePath -Destination $moveToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue
56+
$e | Should BeNullOrEmpty
57+
$fooPath | Should Not Exist
58+
$newFooPath | Should Exist
59+
$booPath | Should Exist
60+
$barPath | Should Exist
61+
$newFooPath | Should ContainExactly $fooContent
62+
}
63+
It "Can move to different directory, filtered with -Filter" {
64+
Move-Item -Path $filePath -Destination $moveToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue
65+
$e | Should BeNullOrEmpty
66+
$booPath | Should Not Exist
67+
$newBooPath | Should Exist
68+
$barPath | Should Exist
69+
$fooPath | Should Exist
70+
$newBooPath | Should ContainExactly $booContent
71+
}
72+
73+
It "Can rename via move, filtered with -Include" {
74+
Move-Item -Path $filePath -Destination $renameToPath -Include "bar*" -ErrorVariable e -ErrorAction SilentlyContinue
75+
$e | Should BeNullOrEmpty
76+
$renameToPath | Should Exist
77+
$barPath | Should Not Exist
78+
$booPath | Should Exist
79+
$fooPath | Should Exist
80+
$renameToPath | Should ContainExactly $barContent
81+
}
82+
It "Can rename via move, filtered with -Exclude" {
83+
Move-Item -Path $filePath -Destination $renameToPath -Exclude "b*" -ErrorVariable e -ErrorAction SilentlyContinue
84+
$e | Should BeNullOrEmpty
85+
$renameToPath | Should Exist
86+
$fooPath | Should Not Exist
87+
$booPath | Should Exist
88+
$barPath | Should Exist
89+
$renameToPath | Should ContainExactly $fooContent
90+
}
91+
It "Can rename via move, filtered with -Filter" {
92+
Move-Item -Path $filePath -Destination $renameToPath -Filter "bo*" -ErrorVariable e -ErrorAction SilentlyContinue
93+
$e | Should BeNullOrEmpty
94+
$renameToPath | Should Exist
95+
$booPath | Should Not Exist
96+
$fooPath | Should Exist
97+
$barPath | Should Exist
98+
$renameToPath | Should ContainExactly $booContent
99+
}
100+
}
14101
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.