Comments (3)
It's a trade-off. Technically your approach is faster but the difference is negligible. An argument could be made that the code I'm using now is a bit clearer, especially for beginners.
#convert the parent path into a real file system path
$parent = Convert-Path -Path (Split-Path -Path $path)
#reconstruct the path
$realPath = Join-Path -Path $parent -ChildPath (Split-Path -Path $path -Leaf)
There are often multiple ways to achieve a result in PowerShell and which path you choose may depend on more than writing the shortest code possible.
from psscripttools.
multistep approach sometimes confuses, but it is up to you
from psscripttools.
I was wrong. $path could be a new file and then resolve-path would throw unrecoverable error. So your solution is safe.
from psscripttools.
Related Issues (20)
- ConvertTo-AsciiArt fails HOT 1
- [Question] Mystical Test-WithCulture HOT 2
- Function "Get-FolderSizeInfo" can throw exception HOT 4
- [Bug]: Show-ANSISequence -Background includes foreground HOT 1
- [Request]: Get-FolderSizeInfo long file/folder names enabler HOT 13
- Add parameter to Get-TypeMember HOT 1
- Hide common .NET methods in Get-TypeMember HOT 2
- Add CimClass member command HOT 2
- Sort Get-ParameterInfo output HOT 1
- Get-CommandSyntax by provider HOT 1
- Get-GitSize failing to return a value. HOT 1
- [Bug]: Unable to install HOT 4
- [Bug]: Get-WindowsVersion/Get-WindowsVersionString on non-English based systems HOT 6
- [Bug]: Convert-EventLogRecord Fails to Parse Bits-Client XML due to Id value HOT 2
- [Bug]: Conflict with NTFSSecurity module causes PSScriptTools to fail to import HOT 2
- [Bug]: get-foldersize and user profile files HOT 8
- ANSI style on powershell 7 when PSStyle is defined HOT 2
- [Request]: Improved usage of Get-ModuleCommand HOT 2
- Get-PSUnique enhancement HOT 2
- [Bug]: Invoke-RestMethod error on Get-WhoIs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from psscripttools.