Solved

Rename Files to Include Full Path in File Name

Posted on 2013-11-27
3
298 Views
Last Modified: 2013-12-03
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
Comment
Question by:zabac
3 Comments
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
Do you want them to stay in the original location?  So the full name would be:

\folder1\folder2\folder1-folder2-file1
0
 

Author Comment

by:zabac
Comment Utility
Yes they should stay in the original folders,
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
Comment Utility
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
}

Open in new window


It will rename all files inside a folder and subfolders.

HTH,
Dan
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you Lost your Administrator password for Windows XP, Vista, or 7 this CD will help you reset the password to blank so you can log in. Once in you should change that blank password to something!! Download the ISO on this page http://www.spl…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now