PoshCode Archive  Artifact Content

Artifact 0c704f65dd6e6f79f81026332e6c387b2f339bbabada1b7dd7b911dbedbe5b32:

  • File Renaming-folder-names.ps1 — part of check-in [909ba69e57] at 2018-06-10 14:07:49 on branch trunk — I just want to rename the folder names in particular path where folder name starts with keep all characters by dropping if “12_” before the file name. I am able to rename it but not able to get log file for the following script. (user: Srinu size: 999)

# encoding: ascii
# api: powershell
# title: Renaming folder names
# description: I just want to rename the folder names in particular path where folder name starts with keep all characters by dropping if “12_” before the file name. I am able to rename it but not able to get log file for the following script.
# version: 0.1
# type: script
# author: Srinu
# license: CC0
# x-poshcode-id: 6088
# x-archived: 2015-11-13T23:43:39
# x-published: 2015-11-12T17:06:00
#
#
$Folders = Get-ChildItem 'E:\Root Folder\12_*'

$collection = $()
Foreach ($Folder in $Folders)

{

$status = @{ "OldFolderName" = $Folder.Name; "NewFolderName" = $Folder.Name.Substring(3); "TimeStamp" = (Get-Date -f yyyy:MM:dd-hh:mm:ss) }

$NewFolderName = $Folder.Name.Substring(3); 
Rename-Item -Path $Folder -NewName $NewFolderName

New-Object -TypeName PSObject -Property $Status 
  
}

$collection | Out-File D:\$((Get-Date).ToString('yyyyMMdd'))_Renaming_Folder_Names_script_Log.txt -Append