1

I would like to create a .bat file in order to download and make following operations on 2 files (FILE1-Date.7z & FILE2-Date.7z) whose names are updated with "Date" information everyday. The batch file should do the below operations automatically ;

  1. Download FILE1-Date.7z & FILE2-Date.7z from internet page (i.e. https://collaboration.xxxgroup.com) into specified folder (D:/etc...), and this page requires username & password.

  2. Extract the files (file type is .mdb) inside .7z files to the same folder in which .7z files exist

  3. Delete old (existing) files (FILE1.mdb & FILE2.mdb) in the folder

  4. Rename FILE1-Date.mdb to FILE1.mdb & FILE2-Date.mdb to FILE2.mdb

Is it possible to do these operations by using a batch file or I need to use a totally different tool? Any suggestions?

NOTE : Changed "intranet" with "internet" in step 1, and added more details about web site that I will download the files. Also changed naming format of file WAS: FILE_Date BECOME: FILE-Date (example: LANGUAGES-26-01-2015)

NT.
  • 1,715

1 Answers1

2

You can use a batch file to do this. Without more details, it's hard to provide specifics, but in general, do the following:

  • Use the copy command to copy from the intranet to the specified folder.
  • Use %PROGRAMFILES%\7-Zip\7z.exe for extracting files and overwriting older ones. More Help Here.
  • Use the following for getting the current date:
    set DT=

    for /f "skip=1 delims=" %%A in ('wmic os get localdatetime') do (
        if not defined DT set DT=%%A)

    set YYYY=%DT:~0,4%
    set MM=%DT:~4,2%
    set DD=%DT:~6,2%
    set DATE=%YYYY%_%MM%_%DD%
  • Use the following to rename your file_date.mdb files to file.mdb:
    for /f "tokens=1,2 delims=_" %%A in ('dir /b *.mdb') do ren %%A_%%B %%A.mdb

This should help get you started. Please post a new question with specifics on what you have tried and what isn't working if you run into troubles crafting the batch file.