We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Batch File Help!

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\august.dat i can do this manually but thought i'd seek some assistance after trying unsuccessfully to do this is 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\august.dat

I'd do this on a weekly or monthly basis probably.

All help appreciated.

Thanks,
Paul

Comments

  • fguk
    fguk Posts: 255
    100 Posts
    Forumite
    Paul

    So paul110.dat is copied and the new file becomes august.dat, leaving paul110.dat as it was?

    And you want the batch file to ask you which version of the paul###.dat file you wish to copy?

    Whatshould happen to the august.dat file when you try and copy the paul###.dat file a second time?
  • Something like:
    setlocal
    set /P filenum=Please enter file number:  
    if "%filenum%" == "" exit /B
    copy C:\temp\Paul%filenum%.dat C:\temp\august.dat
    
  • Sorry...think I should have been clearer.

    What I want to do is double click the batch file...it would then prompt me for the file number and create a copy of this file.

    So far I have come up with this:

    I:
    cd "\Info\Data\PJTest"
    COPY CDSWOD__%1.dat Extract.dat

    This works fine if i open the command prompt and pass a parameter to the batch file but i would like it to run with more automation by clicking on the batch file and entering the file number.

    My reason for doing this is that I am linking the extract.dat file into a MS Access database and by coping the file to Extract.dat is will solve the problem of having to relink.

    Thanks,
    Paul
  • fguk
    fguk Posts: 255
    100 Posts
    Forumite
    Yep, ok, I see.

    I think Chippy has got the code for you then.
  • If you want the batch file to accept an optional file number parameter and prompt for it if not supplied:
    setlocal
    set filenum=%1
    if "%filenum%" == "" set /p filenum=Please enter file number:  
    if "%filenum%" == "" exit /B
    copy C:\temp\Paul%filenum%.dat C:\temp\august.dat
    
    For more flexibility and a tidier user interface, use VBScript or JScript instead of DOS batch language.
  • Thanks for your help on this!! Much appreciated :T
  • Would you mind explaining what the /B and /P do?
  • set /P prompts for a value and sets the variable to that value.

    exit /B exits the current batch script instead of the command window. Useful if you've opened a command window and are running the batch script from there.

    Type help set and help exit from a command prompt for more info.
This discussion has been closed.
★ ★ ★ Meet your Ambassadors

Categories

  • All Categories
  • 356K Banking & Borrowing
  • 255K Reduce Debt & Boost Income
  • 456.3K Spending & Discounts
  • 248.5K Work, Benefits & Business
  • 606.4K Mortgages, Homes & Bills
  • 179.1K Life & Family
  • 264.2K Travel & Transport
  • 1.6M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.7K Read-Only Boards
Quick Search

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.