PowerShell code below shows how to work or play with files and folders.
#Get the file name only using “.BaseName”
$FileNameOnly = (Get-ChildItem -File -Path "C:\temp\").BaseName
$FileNameOnly = (Get-ChildItem -File -Path "C:\temp\").BaseName
#Get the full path of
the file using “.FullName”
$Full_Path = (Get-ChildItem -File -Path "C:\temp\").FullName
#Get the parent folder
of the path of the file using “.DirectoryName”
$ParentFolder = (Get-ChildItem -File -Path "C:\temp\").DirectoryName
#Get the file with the extension using “.Name”
$FileName_withExtension = (Get-ChildItem -File -Path "C:\temp\").Name
`n – starts a new line after the current line
Write-Output "FileNameOnly: $FileNameOnly
`n"
Write-Output "Full_Path: $Full_Path `n"
Write-Output "ParentFolder: $ParentFolder
`n"
Write-Output "FileName_with_Extension: $FileName_withExtension `n"
Write-Output "**********`n"
Sample Output:
FileNameOnly: vol_drive zip_error
Full_Path: C:\temp\vol_drive.csv
C:\temp\zip_error.txt
ParentFolder: C:\temp C:\temp
FileName_with_Extension: vol_drive.csv
zip_error.txt
**********
#Concatenate the output with another string
and display in one line
Write-Output ("Parent_Folder: " + $_.DirectoryName + "`n")
Write-Output ("Parent_Folder: " + $_.DirectoryName + "`n")
$_.- this holds the value
from Get-ChildItem
command
$Path2Folder = "c:\temp"
Get-ChildItem -Path $Path2Folder -Recurse | ForEach-Object {
Write-Output ("Parent_Folder: " + $_.DirectoryName + "`n")
Write-Output ("Full_Path: " + $_.FullName + "`n")
Write-Output ("File_Name_Only: " + $_.BaseName + "`n")
Write-Output ("FileName_with_Extension: " + $_.Name + "`n")
Write-Output "-------`n"
}
Sample Output:
Parent_Folder: C:\temp
Full_Path: C:\temp\vol_drive.csv
File_Name_Only: vol_drive
FileName_with_Extension: vol_drive.csv
-------
Parent_Folder: C:\temp
Full_Path: C:\temp\zip_error.txt
File_Name_Only: zip_error
FileName_with_Extension: zip_error.txt
-------
Cheers. Till next time.
================================
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
Heaven's Dew Fall Prayer app for Android :
Catholic Rosary Guide for Android:
Comments
Post a Comment