简体   繁体   中英

.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!

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

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.*
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM