• 0

Batch file rename folders


Question

Hi all,

I know this isn't technically programming but I didn't see anywhere it fit better. Feel free to move it.

Okay, so what I'm trying to accomplish is adding a random combination of numbers or letters or both to the beginning of a large list of files in batch. So far I've tried:

For /D %%i IN (*) DO rename "%%i" "%random%%%i"[/CODE]

But batch only runs a single random number with this and sets them all to that same number.

I've also tried adding something like "%%~zi" to the rename which grabs the file size but since it's a folder this returns 0.

The creation date tag "%%~ti" would work if chopped down to the last milliseconds but it appears the only way to even get at this value is to save it as a text file but it appears batch doesn't allow you to pull the content of a text file into a variable whilst inside of the FOR command.

and now I'm all out of ideas..

I have python installed so if anyone knows of a script to accomplish this I'm all ears but I haven't worked with it enough myself to accomplish this in a reasonable amount of time.

Thanks for reading,

~hobbly

Link to comment
https://www.neowin.net/forum/topic/1116891-batch-file-rename-folders/
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Managed to modify a python script to do what I need. In-case someone stumbles on this thread with a similar problem I used:

import os, random

path = '[location of folders]'
listing = os.listdir(path)
os.chdir('[location of folders]')
for infile in listing:
os.rename(infile, str(random.randint(10,99)) + infile)[/CODE]

Original credit to this guy.

This topic is now closed to further replies.
  • Posts

    • Microsoft bans LibreOffice developer's account without warning, rejects appeal by David Uzondu Recently, we reported on LibreOffice, accusing Microsoft of intentionally using complex file formats as a tactic to lock in users to Microsoft Office, hindering open source alternatives like LibreOffice. Now, Microsoft has banned LibreOffice developer, Mike Kaganski, from using its services, citing an "activity that violates [its] Services Agreement". According to Mike, this happened last Monday when he tried to send a technical email to the LibreOffice dev mailing list, which is a normal part of his routine, but Thunderbird returned an error saying the message couldn't be sent. His account was blocked upon retry, and he found himself completely logged out of his Microsoft account. Kaganski guessed that his mail and account were getting flagged by a bot or something, since he was quite sure that nothing in the mail violated Microsoft's terms of service. So he decided to file an appeal, a process which later made him call Redmond "miserably incompetent in IT." The automated system asked for his phone number, which he provided, only to be greeted by a "Try another method" error message. The problem was that there was no other method offered. He then decided to reach out to Microsoft support directly. After some digging, he found a link to contact the team, and there it was, a button asking him to "Sign in to Contact support". Now, you might go, "Hold up, how is he supposed to sign in to contact support when his problem is that he can't sign in in the first place?" As Kaganski himself put it: He eventually got to use his wife's account to file an appeal and finally received a message from support. The instructions inside asked him to go to the sign-in page and, when told the account is blocked, provide a phone number. However, Microsoft ignored his detailed report of the failing process, marked his ticket as resolved without any real action, and simply closed it. He is yet to recover his account. As for the email he was trying to send, he was later able to use Gmail, and it went through with no problem. If you are interested, you can read the full email for yourself and see if it violates Microsoft's services agreement. Mike's not the only person who's had their account locked recently, with seemingly no way to recover it. On the 17th of last month, Reddit user u/deus03690 shared how Microsoft locked their account, which, among other things, contained 30 years of "irreplaceable photos and work" on OneDrive. Their appeal, like Mike's, has been fruitless so far. The user said Microsoft reached out 10 days later, asking them to fill out a recovery form and promising to help them "every step of the way," but they haven't heard from the company since.
    • It's like Microsoft hasn't learned anything from Internet Explorer fiascos. Or they weren't slapped hard enough financially for it...
    • Yes they're payroll taxes with some of it linked to share-based compensation for employees. So when the stock price was rising in q2 these charges also increased.
    • Stopped using paypal as much as I possibly can after the whole Honey mess. Their entire business model essentially is to be a trustworthy middleman and they lost all of it by deciding to do shady things without telling the users. Well done Paypal.
    • I need someone to explain to me what "passkey" is and what happens if my device crashes and is not recoverable.
  • Recent Achievements

    • Apprentice
      MikeK13 went up a rank
      Apprentice
    • Week One Done
      andeyhawk65 earned a badge
      Week One Done
    • First Post
      Jake2530 earned a badge
      First Post
    • Explorer
      Deranox went up a rank
      Explorer
    • Week One Done
      John Volks earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      686
    2. 2
      ATLien_0
      259
    3. 3
      Xenon
      178
    4. 4
      neufuse
      135
    5. 5
      +FloatingFatMan
      100
  • Tell a friend

    Love Neowin? Tell a friend!