Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Prompt
Gui, Font, s12, Tahoma
Gui, Add, Text, x12 y9 w110 h30 , Output folder:
Gui, Add, Button, x502 y9 w100 h40 gBrowseButton, Browse
Gui, Add, Text, x132 y9 w360 h30 , vOutputFolder
Gui, Add, Text, x12 y49 w250 h20 , Paste Full File Paths (1 per line):
Gui, Add, Edit, x12 y79 w590 h200 vFilePaths,
Gui, Add, Button, x492 y299 w120 h50 gStartButton, Start
Gui, Show, x127 y87 h364 w622, New GUI Window
Return
GuiClose:
ExitApp
BrowseButton:
Gui, Submit, NoHide
FileSelectFolder, OutputFolder, 3, Select output folder
Gui, Submit, NoHide
Return
StartButton:
Gui, Submit, Hide
FileDelete, %A_ScriptDir%\batch_file.bat
FileDelete, %A_ScriptDir%\errorlog.txt
; Split file paths into an array
StringSplit, FilePathsArray, FilePaths, `n
; Loop through the file paths array
Loop, % FilePathsArray0
{
; Skip empty rows
if (FilePathsArray%A_Index% = "")
continue
; Check if file exists
if (!FileExist(FilePathsArray%A_Index%)) {
FileAppend, %FilePathsArray%A_Index% does not exist.`n, %A_ScriptDir%\errorlog.txt
continue
}
; Check if file is a folder
if (A_IsDir(FilePathsArray%A_Index%)) {
FileAppend, %FilePathsArray%A_Index% is a folder, not a file.`n, %A_ScriptDir%\errorlog.txt
continue
}
; Extract file name from file path
FileName := RegExReplace(FilePathsArray%A_Index%, "(.*[\\\/])", "")
; Extract source path from file path
FileSourcePath := RegExReplace(FilePathsArray%A_Index%, "(.*)[\\\/].*", "$1")
; Append robocopy command to batch file
FileAppend, robocopy "%FileSourcePath%" "%OutputFolder%" "%FileName%" /tee /ts /v /fp /np /copy:dat /w:0 /r:0 /log+:"%OutputFolder%\log.txt"`n, %A_ScriptDir%\batch_file.bat
}
MsgBox, Batch file created successfully at %A_ScriptDir%\batch_file.bat.
Return