Powershell - Assigning unique file names to duplicated files using list inside a .csv or .txt -


Never designed such a thing which in reality is to remove information from inside a file and direct that data File name needs to be applied.

I would like to create a script which is a simple one. Csv or text file is included with a single identifying list and it is a batch of duplicate files (they all have the same content) to share a different name as a 3-digit number attached as a common name prefix Those are allocated.

For example, suppose the list of files is like this:

  • 001_test.txt
  • 002_test.txt
  • < Li> 003_test.txt
  • 004_test.txt
  • 005_test.txt

etc.

Then include my .csv alphabet

  • Beta.txt
  • Charlie.txt
  • Delta.txt
  • Echo .txt
  • etc.

    I tried to see similar examples, but I have failed miserably

    EDIT: I have not saved the previously modified items, but here The basic script in which I was messing:

      $ file_server = Read host "Enter file server IP address" $ rootFolder = 'C: \ TEMP \ GPO \ source \ 5' Gate- ChildItem -LiteralPath $ rootFolder -Directory | Where-object {$ _. Name -as [System.Guid]} | For every object, {$ directory = $ _ Full name (Get-content "$ directory \ gpreport.xml") | {$ _- "99.999.999.999" for every object, $ file_server} | Set-content "$ directory \ gpreport.xml" #} etc}  

    I think this is to change a string inside a file, though. I have to replace the file name with another file (which is not to change its name), while the contents of the files are not changed, whose name has been changed.

    Then you want to rename similar files with those files listed in a text file. OK, here's your solution (surname listed in the alias): Gate-content (GC), gate-child item (GCI), ou (?), Rename-item, for eca (%)

    $ Name = "dog.txt" #File for a list of new names, including $ name = gc c: \ temp \ Namelist.txt #Path, filename, name 001_ prefix $ path = " C: \ Temp "$ i = 0 = path to search GCI $ path? {$ _ Name match "\ d {3} _ $ name".} |% {Rename-item $ _FullName $ NewNames [$ i] ;. $ I ++}

    Tested as a job it takes a list of your new names and saves it as an array, then it defines your file name, path , And sets $ i as a counter, then for each file that matches your pattern, it returns the item number $ i , And then increases a number and moves $ i to a number and Well as the body.Why lived next file


    Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -