Solved

Renaming using Powershell

Posted on 2011-09-19
6
637 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
  • 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 68

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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 68

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 is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A brief introduction to what I consider to be the best editor for PowerShell.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

20 Experts available now in Live!

Get 1:1 Help Now