Jump to content
Sign in to follow this  
hymes

Convert Drive Input bat script to Autoit

Recommended Posts

hymes

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

Share this post


Link to post
Share on other sites
JLogan3o13

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 :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
rudi

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!

Share this post


Link to post
Share on other sites
hymes

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

Share this post


Link to post
Share on other sites
rudi

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!

Share this post


Link to post
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
Sign in to follow this  

×