Solved

Renaming using Powershell

Posted on 2011-09-19
6
644 Views
Last Modified: 2012-05-12
Question: I have over 400 directories and within each of those directories there is a *.ini file that I need to query for a value.  Once I have that value I need to rename the text document in that directory, that value.  I'm looking at accomplishing this task in powershell since the rest of the application is powershell.

Below is an example

File 1
   - File 1a
      - document1.ini (The value that I need resides in this *.ini file)
      -document1.txt (The value that I found in document.ini, I need to rename this file to that value)

File 2
   -File 2a
        -document2.ini (the value that I need resides in this *.ini file )
       -document2.txt (The value that I found in document2.ini, I need to rename this file to that value)

0
Comment
Question by:wnbtechnology
[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
  • 2
6 Comments
 
LVL 2

Expert Comment

by:gazm81
ID: 36563435
is there only one value or entry in the ini file?
is there only one file in each folder?
0
 

Author Comment

by:wnbtechnology
ID: 36563516
There is only one value in the ini file.. The entry format is like this: Value=123456789 (I need only "123456789", i need to parase out "Value").

There is only one *.text file in each folder and only one *.ini file in each folder
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 125 total points
ID: 36563669
Something like this?
gci C:\StartFolder -recurse -Filter *.ini | % {
  $txt = gci ($_.DirectoryName + "\*.txt")
  rename-item $txt ((gc $_.Fullname).Split("=")[1] + ".txt")
}

Open in new window

0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:wnbtechnology
ID: 36566879
Qlemo,
     I'm getting an error "Method invocation failed because [System.Object[]] doesn't contain a method named 'split' at line:1 char:139

Below is a little better example of the structure.

C:\folder\test

            -12345678.folder1
                        -Folder 1
                             -document 1.ini <<The value resides in this file ex: value=125458456
                             -test.txt<<the value that was captured in document 1.ini,I need to rename this file to that value 125458456 minus the "value" word. The end result will be 125458456.txt instead of test.txt

            -23452345.folder1
                        -Folder1
                            -document 1.ini <<The value resides in this file ex: value=123456789
                            -test.txt<<the value that was captured in document 1.ini,I need to rename this file to that value 123456789 minus the "value" word. The end result will be 123456789.txt instead of test.txt
       

          -0998767475.folder1
                         -Folder1
                              -document 1.ini <<The value resides in this file ex: value=987654321
                              -test.txt<<the value that was captured in document 1.ini,I need to rename this file to that value 987654321 minus the "value" word. The end result will be 987654321.txt instead of test.txt
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 36567748
The (already tested) script has been applied against your folder structure, and with success. I do not get that error message.
Is
    (gc "c:\folder\test\12345678.folder1\Folder 1\document 1.ini").Split("=")
working?
0
 

Author Closing Comment

by:wnbtechnology
ID: 36716484
I didn't use the exact solution that was provided.  I was able to use some of the powershell cmdlets that were provided to come up with another way of renaming the files that I needed renaming.

Thank you for all your help Qlemo
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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