dos commands, or file-rename

Blitz3D Forums/Blitz3D Beginners Area/dos commands, or file-rename

CS_TBL(Posted 2004) [#1]
Hi,

In Qbasic there was a SHELL command, which you could use to perform dos operations.. is there such a command in B(+) ?

If no, how do I rename a file in B(+) ? (in a typical contruction with ReadDir, NextFile etc.) I just want to make some app that renames a great number of files according to my conditions..


eBusiness(Posted 2004) [#2]
Well, there is always copyfile: delete old file, but as far sa I know there is no true rename command.


Stoop Solo(Posted 2004) [#3]
There's no specific rename command in Blitz, but you can copy and delete files, so you could use this:

CopyFile "c:\old.txt","c:\new.txt"
DeleteFile "c:\old.txt"


You can't really have a "shell" type command now, because of running in Windows. It was different where QBasic etc were concerned, because they were running from within a command environment already.

As far as running external programs is concerned, you can do it via the ExecFile comand, although this can only execute other programs. It would work the same way as the "run" comand line thingy in the start menu. You can use it to instruct Windows to open up any file (with the associated viewer if required). So you would only be able to use it to run the command interpreter. Though the command interpreter has copy and rename, amongst other commands, you wouldn't be able to use it to copy or rename a file, as you would not be able to pass the command interpreter any commands.

Bear in mind also that if you do open a file up with ExecFile, that application will then get the focus.


big pete(Posted 2004) [#4]
outfile=WriteFile("h:\temp.bat")
WriteLine(outfile,"rename h:\peach.exe peach.jpg")
CloseFile outfile
ExecFile("h:\temp.bat")
;DeleteFile("h:\temp.bat")

This seems to work fine- upto the point where I enable the last line, so I think there's no way to avoid an ugly .BAT file from staying on the harddisk. :/


soja(Posted 2004) [#5]
There are multiple ways to rename a file. Here's one way:
CreateProcess("cmd.exe /c rename file1 file2")

Of course you have to use the right command interpreter depending on the OS.

Here's another way which should work on all systems:
;.lib "msvcrt.dll"
;RenameFile%(source$, dest$):"rename"

result = RenameFile("file1", "file2")
If Not result Then Notify "Success!" Else Notify "Failure."
End


I would not recommend using the copy/temp file method.