Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Help...please  (Read 2182 times)

0 Members and 1 Guest are viewing this topic.

schnadi_uk

  • Guest
Batch File Help...please
« on: November 14, 2006, 04:22:10 AM »
Hi everyone...

Could anyone help me with a small problem i have...

OK...what i'm after achieving is to simply create a small batch file which copys a named dat file. For example, I would like to copy a file called C:\temp\Paul110.dat to C:\temp\All.dat i can do this manually but thought i'd seek some assistance after trying unsuccessfully to do this in a batch file

What i want my batch file to do is prompt me for a file number which in this case is 110 and to copy the data to C:\temp\All.dat

All help appreciated.

Thanks,
Paul

QBasicMac

  • Guest
Re: Batch File Help...please
« Reply #1 on: November 14, 2006, 05:35:07 AM »
So you have a lot of files in directory C:\temp
Paul109.dat, Paul110.dat, Paul111.dat, ...

From time to time, you want to select one such as Paul110.dat and copy it to All.dat, replacing the previous contents of All.dat so that you have two equal files: All.dat and Paul110.dat.

If you don't insist on prompting, you could simply have this

@echo off
if x%1==x (
  echo You forgot to say what file you wanted to copy
  goto Adios
)
if not exist c:\temp\Paul%1.dat (
  echo There is no file named Paul%1.dat in c:\temp
  goto Adios
)
copy c:\temp\Paul%1.dat c:\temp\all.dat
:Adios


Mac

gpl



    Apprentice
  • Thanked: 27
    Re: Batch File Help...please
    « Reply #2 on: November 14, 2006, 07:54:04 AM »
    Even better ... ask the user if they forgot
    Graham

    @echo off
    if x%1==x (
      Set /P filenum=You forgot to say what file you wanted to copy:
    )  else (
    Set filenum=%1
    )
    if not exist c:\temp\Paul%filenum%.dat (
      echo There is no file named Paul%filenum%.dat in c:\temp
      goto Adios
    )
    copy c:\temp\Paul%filenum%.dat c:\temp\all.dat
    :Adios

    QBasicMac

    • Guest
    Re: Batch File Help...please
    « Reply #3 on: November 14, 2006, 02:28:38 PM »
    Quote
    Set /P filenum

    Yeah, Graham - That answers the users "prompt me" need.

    I don't use that because Set /P does not work on WindowsNT (in cmd or command or QBasic's funny command)

    So I cannot prompt from a BAT file. If I ever have the need, I use a QBasic program (which comes free with WindowsNT, presumably to overcome limitations like that - LOL)

    Mac