I'm trying to create a batch file to automate a process: i need to check into a folder if files name have "A-" prefix If not, i need to add it. I can name the folder like the prefix if this can help!

Thank you!

  • ok, what did you try so far?
    – SimonS
    Oct 28, 2016 at 9:22
  • Does it have to be a batch?
    – Seth
    Oct 28, 2016 at 9:29
  • Which operating system?
    – Atzmon
    Oct 28, 2016 at 9:30
  • I have win10. Should not be a batch, i know only this.
    – Genko
    Oct 28, 2016 at 9:37
  • gci "C:\somepath" | ? { $_.Name -notlike 'A-*'} | % { gi $_.FullName | rni -NewName "A-$($_.Name)"}in powershell
    – SimonS
    Oct 28, 2016 at 9:38

2 Answers 2


If it doesn't have to be a batch file, then you could use ReNamer. You can save your renaming rules as a preset and use it to rename your files/folders via command line or scheduled tasks, automatically.

ReNamer - A Prefix

Once you save your rules in as a preset (e.g. A-Preset) then you can use it for automatic renaming via command line:

ReNamer.exe /rename "A-Prefix" C:\Test

The rules above simply remove existing A- prefix and then add it back in. Files which already have A- prefix will remain unchanged after a renaming operation.

Using a GUI to configure renaming rules and test them may be easier than having to tinker with complex batch files.

  • Perfect for end users! Thanks a lot. It would be great if the rules could be exported to REGEX. That'd be really useful!
    – Metafaniel
    Aug 14, 2018 at 18:14

This is simple with JREN.BAT - a regular expression renaming utility. JREN is pure script (hybrid batch/JScript) that runs natively on any Windows machine from XP onward - no 3rd party exe file is required. Full documentation is embedded within the utility - use JREN /? from the command prompt to get help. (jren /?? for paged help)

To conditionally add the A- prefix to all files within the current folder:

call jren "^" "A-" /fx "A-*"

The first argument matches the beginning of the file name. The second argument "replaces" the match with "A-" (Inserts "A-" at the beginning). The /FX option excludes all files that already begin with "A-"

You can specify a different folder by adding the /P "yourPath" option.

You can have the prefix match the parent folder name by adding a FOR loop. For example, suppose you have a catalog of mp3 files within "c:\music" Each folder under "\music" represents an album, and each mp3 within an album folder is a song on that album. You could use the following to prefix each song with the album name, only if it is not there already:

@echo off
for /d /r "c:\music" %%F in (*) do call jren "^" "%%~nxF-" /p "%%F" /fm *.mp3 /fx "%%~nxF-*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.