• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Can a batch file do this?

TechnoPro

Golden Member
I'm looking for a method of interactively renaming a file via batch file.

I don't know if this can even be done, but I would like the batch file to ask the user to imput a new name for the file, the user types it in and presses enter, and the file is renamed with the value that the user typed.

Here's an example:

Assume file test.txt located on the C: drive.

The batch file, when launched, would display "Please type in a new name" (ECHO command). The user would enter a new name and press enter. That string of text would presumably be assigned as a local variable (using SETLOCAL?). Finally, the script would rename test.txt to whatever the user typed.

Any ideas how this could be done?

----- SOLVED ------

SET /P WHATEVER=

REN test.txt "%WHATEVER%.txt"
 
Originally posted by: Calin
copy "old file" "new file"
del "old file"

OR simpler just ren "old file" "new file"

Calin

Thanks, but that won't do it. My bad - I was unclear with my original post as to my objective.
 
The only challenge is figuring out how to get user input STRINGS. There are a few ways but they are not direct. The only input batchfiles really want from you are single letters (ie for a menu).
 
Originally posted by: sygyzy
The only challenge is figuring out how to get user input STRINGS. There are a few ways but they are not direct. The only input batchfiles really want from you are single letters (ie for a menu).

??
I guess you haven't written batch scripts in quite some time. You can store whatever you want in an environment variable, even with spaces in it.

You can even use set /p to prompt for user input.
 
I didn't knew about the "set /p" thing. And you are correct, all the batch files I written were for the MS-DOS operating system, or using only the capabilities of MS-DOS batch scripting

Calin
 
if you need help, i could whip it up real quick. Honestly, this is very simple stuff. Anybody DOS fan can help you too.

-=bmacd=-
 
Don't prompt them; instead, just accept an argument. All you would then need to do is this:

ren test.txt %1

That's it. Save it, then run it:

yourbatchfile newfilename.txt
 
Sorry but that's the solution I think the OP was trying to avoid. Yours doesn't differ much from him manually typing "ren filename1 filename2"
 
Originally posted by: Jzero
Originally posted by: sygyzy
The only challenge is figuring out how to get user input STRINGS. There are a few ways but they are not direct. The only input batchfiles really want from you are single letters (ie for a menu).

??
I guess you haven't written batch scripts in quite some time. You can store whatever you want in an environment variable, even with spaces in it.

You can even use set /p to prompt for user input.

Problem solved, thank you! That SET /P did the trick. I'm grateful.
 
Originally posted by: TechnoPro
Originally posted by: Jzero
Originally posted by: sygyzy
The only challenge is figuring out how to get user input STRINGS. There are a few ways but they are not direct. The only input batchfiles really want from you are single letters (ie for a menu).

??
I guess you haven't written batch scripts in quite some time. You can store whatever you want in an environment variable, even with spaces in it.

You can even use set /p to prompt for user input.

Problem solved, thank you! That SET /P did the trick. I'm grateful.

:thumbsup: SET /P is a pretty handy command. It's probably one I use the second most right after FOR /F
 
Back
Top