Search code examples
batch-filecd

How to change directory in batch?


I tried writing a prank virus. But the directory does not change. Here is the small code:

mkdir AA
copy open.bat AA
cd /D %AA%
AA.bat

It is supposed to: 1. Make directory name 'AA' in current directory 2. Copy itself to AA 3. Change directory to AA 4. Open open.bat which is in AA directory and start the process again.

But after performing first 2 steps, it does not change the directory and open the open.bat which is in root directory.

All I see in console is: A subdirectory of file A already exists. 1 file(s) copied. A subdirectory of file A already exists. 1 file(s) copied. A subdirectory of file A already exists. 1 file(s) copied. A subdirectory of file A already exists. 1 file(s) copied. A subdirectory of file A already exists. 1 file(s) copied.

and soooo onnn


Solution

  • As AA is not a variable but a path :

    mkdir "AA"
    copy "open.bat" "AA"
    cd "AA"
    call "open.bat"