English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok i have a batch file now i'm trying to make the batch file actually save itself when executed.....so far i have made the Batch file create a directory of it own to save in but i'm not sure how i can make the Batch file save itself to that directory i have made...if there is a Command that you know please would be a great deal to me if you could tell me =P ty very much

2007-03-29 14:38:36 · 6 answers · asked by blazncaczn 3 in Computers & Internet Programming & Design

6 answers

A batch file can absolutely copy itself to another directory while running. In fact, it can even move or delete itself. You can do this by calling a second command processor from inside your original batch file and using the copy command.

Here's my test.bat file that illustrates this.
===================
@echo off
cls
md testdir
start cmd /c copy "c:\test.bat" "c:\testdir\"

=============
To test, create the test.bat file with the command above and run it. It will make the 'testdir' directory and copy itself into the directory.

2007-03-31 01:10:22 · answer #1 · answered by Kevin 7 · 2 1

What are you talking about? A batch file save itself? The batch file IS saved or it wouldn't be running? Are you trying to copy or move the file to another location?

You probably won't get an answer here because this site was not designed to be heavily interactive - odds are, I won't be checking back on this question before it closes (because I don't have time to check back periodically). You would really be better off asking this question on a newsgroup and/or a message board that encourages users to ask each other questions and participate in a dialog. Two sites you can try are www.experts-exchange.com and www.tek-tips.com - I participate on both and when someone comments in a question, everyone is notified and prompted to check back (unlike here).

2007-03-29 21:44:35 · answer #2 · answered by lwcomputing 6 · 0 2

Batch files can't necessarily "save themselves" that I'm aware of unless you start doing scripting - at that point it's a script file and not a batch file.

However... let's say you have a file called "MyBatch.Bat"
You could do this in it...

md C:\NewDir
move c:\MyBatch.Bat C:\NewDir\MyBatch.Bat

and that would move the file.
if you're wanting to write a file, you could just pipe the output to a file and do ECHOs

Not sure what you're actually triyng to accomplish, but those are some ideas.

2007-03-29 23:00:23 · answer #3 · answered by vbslinger 2 · 0 2

Define 'save itself'.

If you mean modify itself and save that while coping, nope.

If you mean, save all the changes to a TXT file using the pipe or redirection command, close the .TXT file and rename it to .BAT as the last command , yup.

2007-03-29 21:47:35 · answer #4 · answered by Necros 3 · 0 2

Can't you just use "copy" and copy it to the new directory with the same name?
copy batfile.bat C:\newfolder\batfile.bat

2007-03-29 21:45:55 · answer #5 · answered by Anonymous · 0 2

lets say your batch file called "test.bat" is on the desktop.

it contains the following two lines:
-------------------------------------------------------------
mkdir test
move test.bat test
-------------------------------------------------------------

this will work for you.. it worked for me!

2007-03-29 21:46:59 · answer #6 · answered by Anonymous · 0 1

fedest.com, questions and answers