Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

newbie .bat help

Jan 20, 2016 10:53AM PST

hello. i am trying to make a .bat file that copies a file to the users desktop, then opens the file that is on the esktop. here is what i
have:

@echo off
copy G:\content\base.bat\viruses\self-replicating.bat C:\Users\mluers\Desktop
:hi
start self-replicating.bat

i am super new at this and i cant find the problem. any help would be appreciated

Discussion is locked

- Collapse -
Re: .bat file
Jan 20, 2016 11:13AM PST

You don't tell what doesn't work. So just a few remarks.
- don't use @echo off while testing
- why a label without a goto?
- I think the "start " is unnecessary, althoug maybe it has some other effect if you remove it
- the first line might work, if that file source file exists and you have write access to the target folder
- the last line only works if the batch file is in the Desktop folder also; if not you either have to add a line with cd before that line, or add the folder to the filename
- this file doesn't replicate - it only duplicates

Kees

- Collapse -
.bat file
Jan 20, 2016 1:19PM PST

i have 2 .bat files. the first .bat file takes the 2nd one and moves it to the desktop of a computer. it also should start the 2nd .bat file. what i am trying to do is plug in the flash drive, run the first file, then be able to unplug the flash drive and allow the copied program to run independently of the flash drive. also, what do you mean by why a label without a goto? with this, "the last line only works if the batch file is in the Desktop folder also" are you saying that i have to move both .bat files to the desktop?

- Collapse -
Re: .bat file
Jan 20, 2016 1:39PM PST

1. You only have to use a label (like :hi) if you have a goto statement to jump to it. You don't have that.
2. The last line executes a file from the folder this batch file is in, because you didn't cd to another folder nor specifiy another folder in the filename

A tip for writing a batchfile: only put commands in it that work if you type them in the command prompt. The command prompt is a perfect test environment for simple scripts, but it doesn't work when you use loops. But this is a simple script.

That way, you don't have .bat questions, but command prompt questions. Any book, web page, tutorial about the command prompt will help if you ask the right question.

Kees

- Collapse -
.bat file
Jan 20, 2016 1:45PM PST

much appreciated

- Collapse -
.bat file
Jan 20, 2016 1:21PM PST

it will start the .bat, but when i unplug the flash drive, it will stop.