Solved

Rename Files to Include Full Path in File Name

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

by:zabac
ID: 39682692
Yes they should stay in the original folders,
0
 
LVL 34

Accepted Solution

by:
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
}

Open in new window


It will rename all files inside a folder and subfolders.

HTH,
Dan
0

Featured Post

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Question has a verified solution.

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

Suggested Solutions

Update 11/3/2014 - Although the below article will get you to relocate the WINSXS folder, Microsoft has finally released a utility to reduce the size of the WINSXS folder. For some reason, it's not that straightforward. It only works on Windows 2008…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

867 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

24 Experts available now in Live!

Get 1:1 Help Now