Solved

Rename Files to Include Full Path in File Name

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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
robocopy 33 116
Scheduled Tasks Tweak 5 42
sql server service accounts 4 42
Windows command prompt command to set default sound 4 42
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…
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 …
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…
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…

828 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