Kyle G
Kyle G

Reputation: 11

.bat file to rename and move files with prompt

I am completely new to this, but I am trying to create a .bat file that will allow me to rename a pair of files within a designated folder and move them into a subfolder. The part I am having trouble with is that I am wanting a prompt to come up to identify/select the files to be renamed and moved.

Example file names are:

A1234, A1235, A1236, B1234, B1235, B1236, etc.

Is there a way to bring up a prompt that allows the user to type the shared name (ex 1234)of the files and rename and move both files to the designated subfolder?

Any and all help would be appreciated!

Upvotes: 0

Views: 371

Answers (2)

Bali C
Bali C

Reputation: 31221

Here you go

@echo off
set /p file=Please type shared name: 
for %%a in (C:\Folder\?%file%.*) do (
move "%%a" subdir
ren "subdir\%%a" newname.*
)

Upvotes: 1

Mukul Goel
Mukul Goel

Reputation: 8467

Suggested approach

for part of problem

part I am having trouble with is that I am wanting a prompt to come up to identify/select the files to be renamed and moved. Is there a way to bring up a prompt that allows the user to type the shared name (ex 1234)of the files and rename and move both files to the designated subfolder?

Do a search operation using wildcard, like "?1234" for the case highlighted above ( should be made generalized for all acceptable and expected patterns "*1234*" is the generic most )

Now do a RENAME inside a For loop on the results obtained by search.

As you suggest you are a newbie with Batch, following tutorials will help you build your file. Look for elements like Variables, For Loop

Batch Tutorial

Upvotes: 1

Related Questions