You can do it this way (let's say your prefix is "AS"): x=1 for k in AS* do y=$((x++)) echo "mv $.mol2 $y.mol2 done The SETLOCAL makes the definition of fname temporary (local) to the batch file. It doesn't matter if fname is already defined with the batch file. FOR variables must be referenced as %%A instead of %A, and %%fname%% is not expanded initially, instead the double percents are converted into single percents and then %fname% is expanded after the CALL. The rules for expansion are different in a batch file. Or you can specify the full path to the batch file when you call it. The batch file will also have to be in your current directory unless the batch file exists in a directory that is in your PATH variable. The batch file will rename files in your current directory. Suppose you had files named like "prefixName.txt", then you would use the script by executing RemovePrefix "prefix" "*.txt" If you want to run the command again with a different prefix, you will have to first clear the definition again.ĮDIT - Here is a batch file named "RemovePrefix.bat" that does the job ::RemovePrefix.bat prefix off If fname is defined prior to running the command, then it will simply try to rename that same file for each iteration instead of the value that is being assigned within the loop. ![]() The CALL causes an extra expansion phase that occurs after the variable has been set, so the expansion works. On the command line the percents are preserved if the variable is not found. Of course that won't work because it hasn't been defined yet. The tricky thing is Windows first attempts to expand %fname% when the command is first parsed. The fname variable is defined for each iteration and then the syntax %fname:*prefix=% replaces the first occurrence of "prefix" with nothing. for %a in (prefix*.txt) do "fname=%a" & call ren "%fname%" "%fname:*prefix=%") It won't work properly if fname is already defined. Next is the command to actually do the renaming. ![]() But here is a solution that should work with most file names.Ĭritical - first you must make sure you have an undefined variable name, I'll use fname set "fname=" If you have lots of files to rename, then ReName is a really good application that is fairly lightweight, but packs a mean punch in the batch processing dept.I don't understand why you can't use a batch file. Additionally, it has the ability to rename folders, process regular expressions, and it supports a variety of meta tags, such as: ID3v1, ID3v2, EXIF, OLE, AVI, MD5, CRC32, and SHA1. ![]() With ReNamer you can combine multiple renaming actions as a rule set, applying each action in a logical sequence, which can then be saved, loaded, and managed within the application. ReNamer is a lightweight and flexible batch file renaming tool that offers standard users the usual renaming features, including prefixes, suffixes, replacements, and case changes, as well as the ability to remove contents of brackets, add number sequences, and change file extensions.įor power users, there is also a PascalScript rule, which allows users to program their own renaming rules.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |