Powershell - Renaming files using a random name from a distionary file RRS feed

  • General discussion

  • I'm trying to rename a series of files in a directory using random names from a dictionary file. I've seen plenty of options using random numbers, but I can't use numbers. My results need to be alphabetically spaced out and numbers places all the files at the top of the sort order.

    • Changed type Bill_Stewart Wednesday, September 4, 2019 9:21 PM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:21 PM Unanswerable drive-by question
    Wednesday, April 17, 2019 4:38 PM

All replies

  • what script do you currently have?

    please remind the forum rules this forum is for scripting questions

    Please remember to mark the replies as answers if they helped.

    Wednesday, April 17, 2019 4:48 PM
  • No script yet, I was trying to work things out using the GetRandomFileName() command but I'm not able to adequately combine this with additional commands to eliminate the random extension. 

    Wednesday, April 17, 2019 6:59 PM
  • ([io.path]::GetRandomFileName() -split '\.')[0]

    It is nearly impossible to understand what you are trying to do without posting your script.  If you do not know how to write a script then take some time to learn the basics and then try yo ask your question.


    Wednesday, April 17, 2019 7:33 PM
  • I didn't come here to be talked down to. If you can't offer any support, keep your mouth shut and let others that can help jump in. If nobody wants to help and they stay silent, that's better than having you tell me to go away and learn something. Part of learning how to do things is asking for help, your comments prevents people from doing that.

    If you have nothing good to say or can't/don't want to help, don't say anything at all.

    Wednesday, April 17, 2019 7:47 PM
  • No offense was intended; it's just that we see tens of scripts requests per week despite a post at the very top of this forum titled, specifically, This forum is for scripting questions rather than script requests (as noted already in the first response to your question).

    As noted in that post, the purpose of this forum is to help you get specific scripting questions answered. We really don't have the resources to write scripts on request.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 17, 2019 7:59 PM
  • Bill...That's a better answer than jrv chose to provide. Thanks
    Wednesday, April 17, 2019 8:07 PM
  • Bill...That's a better answer than jrv chose to provide. Thanks

    My answer was a wild guess because your request is ambiguous.  Without a clear explanation and a script it is not possible to do more than guess.


    Wednesday, April 17, 2019 8:29 PM
  • Read your dictionary file into an array using something like Get-Content and -split. Get a random number using Get-Random and use the Count property (minus 1) of your array as -Maximum. Now you can index into your array with the random number to get a random word.
    Thursday, April 18, 2019 5:11 AM
  • get-childitem | 
      rename-item -NewName { [System.io.path]::GetRandomFileName() } -whatif

    What if: Performing the operation "Rename File" on target "Item: C:\users\admin\foo\file1 Destination: C:\users\admin\foo\t15vohte.zrj".
    What if: Performing the operation "Rename File" on target "Item: C:\users\admin\foo\file2 Destination: C:\users\admin\foo\qalgrhtz.d12".
    What if: Performing the operation "Rename File" on target "Item: C:\users\admin\foo\file3 Destination: C:\users\admin\foo\auajtuxd.d30".

    An opportunity for a script block parameter.  Tab completion is your friend.

    • Edited by JS2010 Thursday, April 18, 2019 2:56 PM
    Thursday, April 18, 2019 12:48 PM