Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Renaming using Powershell

Posted on 2011-09-19
6
Medium Priority
?
647 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 71

Accepted Solution

by:
Qlemo earned 375 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
Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist 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 71

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

Are your AD admin tools letting you down?

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

A brief introduction to what I consider to be the best editor for PowerShell.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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