Solved

# Rename Files to Include Full Path in File Name

Posted on 2013-11-27
304 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

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 500 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

### Suggested Solutions

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …