VOGONS


First post, by CMR779

User metadata
Rank Newbie
Rank
Newbie

I did a search for batch files and this forum section seemed to come up the most so I decided to post this here. Anyway, It's 2025 and I decided to learn a new sill and get better at writing batch files, I'm having some trouble though. My file works, but it doesn't seem to regard anything other than the program calls in it. The other commands seem to be getting ignored. Nothing is getting echoed like it seems it should. Here's a sample:

REM - Rename a File, usage: RENAME <FILE> <NEWNAME>

echo Renaming file.
If %1.==. Goto Inst

copy %1 %2 /v
del %1

Goto End

:Inst
echo Rename a File. Usage: RENAME <FILE> <NEWNAME>
pause
:End

The works. The file is renamed successfully, but nothing else seems to work. If I leave out any filenames for arguments it just gives me "Required parameter missing." as if I had just ran copy by itself. Is there something fundamental I'm misunderstanding about batch files?

Reply 1 of 4, by AlaricD

User metadata
Rank Oldbie
Rank
Oldbie

Encapsulate the variable in quotes and otherwise modify it slightly.

If "%1"=="" Goto Inst

However, this doesn't take into account someone may type garbage in, and so if they don't present two different strings it'll try to copy a file that probably doesn't exist to an unspecified filename, but then they'll get a "file not found" message for that.

Escape the greater than/less than symbols. Those are for file redirection and if not escaped will try to do their function rather than echo as text.

echo Rename a File.  Usage: RENAME ^<^FILE^>^  ^<^NEWNAME^>^

Reply 2 of 4, by CMR779

User metadata
Rank Newbie
Rank
Newbie

Well I think I found one problem, and that was that there is already a rename command. (doh!) I'm still getting a weird file not found error even when the program successfully copies a file. Tested it on MSDOS 6.22 and I'm getting a lot of file not found errors, and in dosbox it creates a file called ^ for some reason. (I'm guessing a bug)

Here is the latest rendition. @echo off is REMed out just so I can see what it's doing.

REM @echo off
REM - Rename a file, usage: RENAME <FILE> <NEWNAME>

If "%1"=="" Goto Inst

copy %1 %2
del %1

Goto End

:Inst
echo Rename a file.
echo Usage: RENAME ^<^FILE^>^ ^<^NEWNAME^>^
:End

Reply 3 of 4, by CMR779

User metadata
Rank Newbie
Rank
Newbie

I've renamed the file rname.bat, I just didn't change it in code yet.

Reply 4 of 4, by myne

User metadata
Rank Oldbie
Rank
Oldbie

You may be getting file not found if they are hidden.

What are you renaming?

I pretty much always use rash.

Attrib - r - a - s - h %1

Have a look at the second last link in my sig.
It's a complex bat. Might give you tips.

I'm still half asleep so I'm sure I'd see the problem normally. I think the "" might be an issue though

rem if [%vtemp2%]==[] xset write=no

Look at that line. If [%1]==[] is a blank check. The [] are only there so it's not actually blank

I built:
Convert old ASUS ASC boardviews to KICAD PCB!
Re: A comprehensive guide to install and play MechWarrior 2 on new versions on Windows.
Dos+Windows 3.11+tcp+vbe_svga auto-install iso template
Script to backup Win9x\ME drivers from a working install
Re: The thing no one asked for: KICAD 440bx reference schematic