Jump to content

Convert Drive Input bat script to Autoit


hymes
 Share

Recommended Posts

Hello, I am very new to this forum and trying to learn as quickly as I can. The reason I am looking into this is I have an existing BAT file that works just fine. I was hoping to make it look nicer using AutoIt. I have included the script I want to convert. Can someone please help me get started. Thanks Alan

@echo off

REM

REM Using robocopy to mirror one folder/drive with another

REM Input is source folder/drive and destination folder/drive

REM Usage source folder input eg. A: and dest eg. B:

REM robocopy will sync/mirror A: to B: and exclude the stuff listed

REM

echo.

set /p SF=What is the Source folder (eg. G:):

set /p DF=What is the Destination folder (eg, I:):

echo.

set /p YNVar=You sure you want to sync "%SF%" to "%DF%" [y/n]?

echo.

if "%YNVar%"=="Y" goto doYES

if "%YNVar%"=="y" goto doYES

goto doNO

:doYES

echo Mirroring/Syncing folders "%SF%" and "%DF%"

echo.

set EXCLUDE=/XD "%SF%\System Volume Information" /XD "%SF%\RECYCLER"

SET WHAT_TO_COPY=/MIR

robocopy.exe %SF% %DF% %WHAT_TO_COPY% %EXCLUDE%

echo.

goto done

:doNO

echo Aborting Action!

:done

pause

Link to comment
Share on other sites

  • Moderators

Hi, hymes, welcome to the forum. To begin with, the AutoIT help file is your best friend. Everything in your bat file can easily be converted. I would suggest looking into the following items in the help file: InputBox, MsgBox, FileCopy, DirCopy. You might also do a forum search for robocopy, to see some examples of what others have done. Once you've read a bit, try your hand at a script, and feel free to post it here if you run into trouble :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Usually we don't handfeed users on this forum. We help users to learn the language and solve problems they have with their code.

As a start:

set /p SF=What is the Source folder (eg. G:):
translates to
$SF = InputBox("", "What is the Source folder (eg. G:):")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi.

Welcome to the forum!

"look nicer" means you want to add a GUI? There is already a GUI for robocopy, search "robocopygui"

Or are you looking for a dialog box to ask for Yes/No ?

A good start is the autoit HelpFile. Search for "variables" and "msgbox()". Install the autoit customized SciTE editor, use the code wizzard to easily create comfortable messageboxes (tools->code wizzard = ALT+w)

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Thanks all for the responses. I will look at the areas you pointed me to and see what I can come up with. To answer Rudi's question, yes for "fun" I wanted to try and make my existing script more "fancy" as in a GUI. I did check out the robocopygui but it still doesn't really do what I wanted. What I want is to do exatly what my script does but yet be a clean, simple, GUI. Especially when my drive letters may change. Robocopygui does do this but it takes more effort to run it than my script. I know being picky, but again, I just wanted a simple GUI to ask the two questions and then perform the robocopy to mirror two disks. I will continue to play around. Thanks again for all the responses and feedback.

Alan

Link to comment
Share on other sites

  • 2 weeks later...

Hi.

1.) Your approach, to simply ask for a drive letter plus a "one-time-OK?" is IMHO extremly dangerous -- In case the user should pick a wrong drive letter, he/she has the rights to delete for the destination side!

robocopy is not only very powerfull at copying files / folders, it's also unbelievable fast in DELETING files / folders at the destination side, that do not exist at the source side, in case the "/mir" switch is used. (what I assume you make use of...)

2.) robocopy can handle UNC paths, so there is no need to use drive letters at all. This isn't advisable anyway, especially when drive letters tend to change -- as you stated.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...