Solved

Rename Files to Include Full Path in File Name

Posted on 2013-11-27
3
306 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
[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
  • Learn & ask questions
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 35

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Determining the an SCCM package name from the Package ID
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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