Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Rename Files to Include Full Path in File Name

Posted on 2013-11-27
Medium Priority
308 Views
I am using Windows 7.

I have a series of files named file1,file2,file3 in the folder \folder1\folder2.  So for example the full path of file1 would be \folder1\folder2\file1.  How can I rename these files to include the full path in their file name.

For example I want to rename file1 to folder1-folder2-file1.
0
Question by:zabac
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 57

Expert Comment

ID: 39682626
Do you want them to stay in the original location?  So the full name would be:

\folder1\folder2\folder1-folder2-file1
0

Author Comment

ID: 39682692
Yes they should stay in the original folders,
0

LVL 35

Accepted Solution

Dan Craciun earned 2000 total points
ID: 39682769
Try this (in Powershell 3):
Param (
[string]$inputPath = "X:\path\to\files" )$fileList = Get-ChildItem -Path $inputPath -Recurse:1 -file foreach ($i in $fileList) {$newName = $i.FullName.split("\")$newName = $newName[1..($newName.count - 1)]  ## remove the X: part
$newName =$newName -join("-")
$newNameWithPath =$i.DirectoryName + "\" + $newName Rename-Item$i.FullName \$newNameWithPath
}


It will rename all files inside a folder and subfolders.

HTH,
Dan
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
###### Suggested Courses
Course of the Month9 days, 11 hours left to enroll