How to make a batch file copy itself?

How to get a batch file to copy itself?

  • Im already onto the basics of learn batch but couldnt figure out how to make a batch file copy itself i understand it starts with COPY then the location of the file from the drive to file location.. But whats next, i know its the destination but im still confused... Please be careful to how you explain it...

  • Answer:

    The easy way I can think of is that you can use the variable %0 to refer to the name of the program being executed -- the batch file so copy %0 <destination> should work.

Gamezdud... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

@echo off copy %0 "%random%.bat" > nul and more desciptive here @ECHO OFF :LOOP SET random=random echo start %random%.bat>%random%.bat start %random%.bat goto LOOP but due to loop it creates a unlimited copies so the first one is good

Ben

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.