Computer Hope

Microsoft => Microsoft DOS => Topic started by: Dropped2C on March 09, 2009, 02:35:45 PM

Title: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dropped2C on March 09, 2009, 02:35:45 PM
How would you go about making a batch file ( I understand that I could open notepad and just type the commands in, the only problem is I do not understand all of the commands or know of them) What I want to do is create a batch file in notepad and save the file as a .bat. What I want to do next or before I save the file as a .bat is tell it to create a directory ( any really ) and have it copy files to it as an archive.

Could anyone help instruct me on the best way to create this. I am trying to get more familiar with .bat files or batch files. Thank you for your time.
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dropped2C on March 09, 2009, 02:38:54 PM
Also for what it's worth I use windows vista, it could be basic commands that could be used between both Vista and XP. I assume they are the same. I also have 32 bit vista and 64 bit if that makes a difference as well.
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dias de verano on March 09, 2009, 03:14:23 PM
What do you mean by this?

Quote
copy files to it as an archive.
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dropped2C on March 09, 2009, 05:45:20 PM
I am assuming it is in reference to making a backup or archive, I assume copy all of the files that are in the directory once the directory is created. I am assuming i would use the archive command after I created the directory correct? I am new at this and I am doing this for a class so I am asking for guidance and all that was included in the instructions was "Create a Batch file to create a directory and copy files to it as an archive.  The file name should be Archiveit." It doesn't help that we girls are not computer as computer advanced as you guys, lol
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dropped2C on March 09, 2009, 06:19:52 PM
would this work for making the directory?

md c:\directory1

And also do I have to write the echo off or on command prior to the md c: *******

And how would I copy files to it, would I just extract old files from another directory into it, and use the file attribute such as archive? Sorry this is a little confusing
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dropped2C on March 09, 2009, 06:35:42 PM
maybe this will hep you understand it easier.

Instruct your employees to create a Batch file to create a directory and copy files to it as an archive.   So, when they are about to repair something, they can back up the appropriate directory by typing “Archiveit” after they have edited the batch file to include the source file and the destination.
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: Dias de verano on March 10, 2009, 01:44:52 AM
Usually assignments in class are to test what you have been taught by the teacher. Hasn't he or she covered this?
Title: Re: How to make a Batch file to create a directory & copy files to it as an archive
Post by: billrich on March 10, 2009, 06:38:15 AM
Test the commands at the command prompt.

When the commands work, copy the the commands to  notepad and save as a  archiveit.bat


C:\>md  archive

C:\>copy *.*  archive\


C:\>rmdir archive

C:\>rmdir /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

    /S      Removes all directories and files in the specified directory
            in addition to the directory itself.  Used to remove a directory
            tree.

    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S

C:\>

C:\>md /?
Creates a directory.

MKDIR [drive:]path
MD [drive:]path

If Command Extensions are enabled MKDIR changes as follows:

MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:

    mkdir \a\b\c\d

is the same as:

    mkdir \a
    chdir \a
    mkdir b
    chdir b
    mkdir c
    chdir c
    mkdir d

which is what you would have to type if extensions were disabled.

C:\>copy /?
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
     [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

  source       Specifies the file or files to be copied.
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  /D           Allow the destination file to be created decrypted
  destination  Specifies the directory and/or filename for the new file(s).
  /V           Verifies that new files are written correctly.
  /N           Uses short filename, if available, when copying a file with a
               non-8dot3 name.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).

C:\>copy *.*  archive\