Jump to content

Copy PDFs from a variable folder to a folder on the Desktop [Beginner Question]

Recommended Posts


Hey Everybody,

as you know im on a very low autoit-level.

My question is: How can i read all PDFs from a Folder wich is open and copy them to a Folder on a Desktop.


The Folder wich contains the PDFs is variable Z:\Projektls\"*"*"*EVERYTIME ANOTHER ENDING"*"*"*"*"
There can be 1 PDF or even 15 PDFs.

i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language :)




Share this post

Link to post
Share on other sites
4 minutes ago, Mag91 said:

i tried it with _FileListToArray and _FileCopy but i Need some help to understand this language

Show what you have as else people have to type up all the code for you, which is the wrong way to learn.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites

Just a form with a start Button
Than he take a variable number from a Excel list and copy it.

the variable number is the projectpath where he has to find the PDFs


i want to make him write the variable number in the Explorer after the path.

i made it with mouseclick and it worked but i want to find a bette way, so i tried

$HWND = WinWaitActive("Projektdetails", "")
ControlClick($HWND, "", "[CLASSNN:ToolbarWindow322; INSTANCE:2; ID:1287]", "LEFT", 1)

but it doesnt work.

But thats not my main Problem i can handle this with mouseclick.

My main Problem is that i have to find the PDFs and copy them to a Folder on the desktop

I tried _FileListToArray and _FileCopy  but i delete it cause i have no idea how it can work.

Here my full code until now.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("BigBag", 188, 48, 553, 270)
$Button1 = GUICtrlCreateButton("Start", 8, 8, 169, 33)
#EndRegion ### END Koda GUI section ###

HotKeySet("{F10}", "stop")

Func STOP()
While 1

While 2
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE

        Case $Button1 ;Start

;=============Find Project===============
sleep (2000)

If ProcessExists ("EXCEL.EXE") Then
    WinActivate ("BigBag_ab_31.01.17.xlsx - Excel")
sleep (500)
Send("{CTRLDOWN}c{CTRLUP}")                                     ;COPY PROJECT NUMBER FROM EXCEL
sleep (500)

ShellExecute ("Z:\Projektdetails\")
WinWaitActive ("Projektdetails", "Projektdetails", 10)
WinMove ("Projektdetails", "", 0, 0, 1000, 750)
sleep (100)
$HWND = WinWaitActive("Projektdetails", "")
ControlClick($HWND, "", "[CLASSNN:ToolbarWindow322; INSTANCE:2; ID:1287]", "LEFT", 1)




Share this post

Link to post
Share on other sites

Don't you prefer to read the excel cell without being forced to have Excel running?

Try This:

; ===========================================================================================
; Include the Excel's udf
; ===========================================================================================
#include <ExcelConstants.au3>
#include <Excel.au3>
#include <FileConstants.au3>
#include <File.au3>

; ===========================================================================================
; Let's going to define where is the Excel file with the information. In case it doesn't exists
; your script will ask you for it.
; ===========================================================================================
Global $ePath = @ScriptDir & "\Test.xlsx"

If Not FileExists($ePath) Then
    $ePath = FileOpenDialog("Select the Excel file", @ScriptDir & "\", "Excel (*.xls;*.xlsx)", $FD_FILEMUSTEXIST)
    If @error Then
        TrayTip("ERROR", "I can't work without a valid Excel file", 0, 2)

; Now we are going to open the Excel file. Take a look at the help file to understand everything.
$1 = _Excel_Open(False, False, False, False, Default)

Global $oExcel = _Excel_BookOpen($1, $ePath, True, Default, Default, Default, Default)

; Change the Sheet name or the cell acording to your excel file.
Global $pathtopdfs = _Excel_RangeRead($oExcel, "Sheet1", "A1")

If Not @error Then ; If everything has gone fine, then now we can close the Excel object

    MsgBox(0, "Path to the pdf folder", $pathtopdfs) ;

    ; As we don't know if the path to the pdfs has a backslash or not, we are gooing to check it
    If StringRight($pathtopdfs, 1) <> "/" Then $pathtopdfs = $pathtopdfs & "\"

    ; Now we are going to check if this path does exist and how many pdf's file are there inside
    If Not FileExists($pathtopdfs) Then
        MsgBox(0, "ERROR!!", "The folder with the pdf's doesn't exist!!!")
        Local $aFileList = _FileListToArray($pathtopdfs, "*.pdf")
        If @error = 1 Then
            MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        If @error = 4 Then
            MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")

        ; If we have found pdf's files inside the path, then we will show them in an array and we will
        ; copy them to the desired folder.
        ; Maybe it would be faster to copy the whole dir, but if you do like this (inside a loop), you'll
        ; only copy the pdf's files and not any other kind of file that could be in $pathtopdfs
        _ArrayDisplay($aFileList, "PDF File(s) Found:")

        For $a = 1 To $aFileList[0] Step 1
            FileCopy($pathtopdfs & $aFileList[$a], @DesktopDir & "\PDF\", 8)


Welcome to the Autoit comunity :bye:


Greets from Barcelona

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

  • Similar Content

    • DynamicRookie
      By DynamicRookie
      Hello there,
      So i need to clean up my directories a bit, so created a script that checks the amount of .lnk type files found and deletes each of them in a For loop.
      To do this task i'm using _FileListToArray function from File.au3 udf, the problem is that the variable assigned to this command dont seem to store any subscripts, i've been trying to figure out what i done wrong but i couldn't
      Variable $a stores local script directory
      Variable $b stores an array with the list of files found
      Variable $d is only for skipping the first subscript (0) that contains the amount of files found.
      The variable $b when used in a For loop returns this error:

      Any help is really appreciated.
      My script is below:
      #Include <File.au3> $a = @ScriptDir $b = _FileListToArray($a, ".lnk", 1, True) $d = 1 For $c in $b If $d <> 1 Then FileDelete($c) Else $d = 0 EndIf Next MsgBox(0, '', "Cleaned " & $b[0] & " links in " & $a) Exit 0  
    • AndyS19
      By AndyS19
      I want to copy just the selected text in an input control and put it to the clipboard, but GuiCtrlRead() always reads all of the text in the control.
      In this test code, when I highlight a  portion of the left control's text and press ^C, I want to copy just that text to the clipboard; but when I highlight a  portion of the right control's text and press ^C, I want to copy all of its text to the clipboard.
      #include <Debug.au3> _DebugSetup(@ScriptName & "_debug.txt", False, 2, "") _DebugOut("=============== " & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ====================") #include <GUIConstants.au3> #include <WinAPI.au3> #include <Array.au3> Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Set OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("Event_GUIClose") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Global $hWnd_MainWin, $iID_Left, $iID_Right _Main() Func _Main() $hWnd_MainWin = GUICreate("test7", 200, 300) $iID_Left = GUICtrlCreateInput("AAA BBB CCC (get Selected text)", 10, 30, 200, 25) GUICtrlSetOnEvent($iID_Left, "handle_left_btn") $iID_Right = GUICtrlCreateInput("DDD EEE FFF (get All text)", 10, 60, 200, 25) GUICtrlSetOnEvent($iID_Right, "handle_right_btn") Local $aAccelKeys[1][2] = [["^c", $hWnd_MainWin]] GUISetAccelerators($aAccelKeys) GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose') GUISetState() ; Make everything visible While 1 Sleep(127) WEnd EndFunc ;==>_Main Func handle_CTRL_C_key() ConsoleWrite("+++: handle_CTRL_C_key() entered" & @CRLF) Local $hCtrl, $ctrlID, $control_classname, $text $control_classname = ControlGetFocus($hWnd_MainWin) $hCtrl = ControlGetHandle($hWnd_MainWin, "", $control_classname) $ctrlID = _WinAPI_GetDlgCtrlID($hCtrl) If ($ctrlID = $iID_Left) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied selected text:" & @CRLF & "==>" & $text & "<==" & @CRLF) ElseIf ($ctrlID = $iID_Right) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied all text:" & @CRLF & "==>" & $text & "<==" & @CRLF) EndIf EndFunc ;==>handle_CTRL_C_key Func Event_GUIClose() Exit (99) EndFunc ;==>Event_GUIClose Func handle_left_btn() ConsoleWrite("+++: handle_left_btn() entered" & @CRLF) EndFunc ;==>handle_left_btn Func handle_right_btn() ConsoleWrite("+++: handle_right_btn() entered" & @CRLF) EndFunc ;==>handle_right_btn
    • Mannyfresh31
      By Mannyfresh31
      First of all IDK if it's OK to post this topic here and if not I'm asking to move it to the right place.
      Anyway I ask for help in the PDF UDF main thread but nobody has answer me yet and I really need help on this.
      See the problem started when I upgraded Autoit to its new version you can see the thread in the following link 
    • Iznogoud
      By Iznogoud
      I am trying to find more information on generating PDF files from AutoIT and found the UDF topic 
      Also found some info on creating .FDF file and use PDFTK for merging, but i can't find info about a custom based layout.
      What i trying to find out is, if it is possible to generate a variable layout. For an example i created a script which is based out 20 fields and every field can contain information. If one of those fields are not filled, it shouldn't be printed on the PDF either.
      To make it more difficult, the PDF should contain a heading, the first 10 fields and then a horizontal line across the PDF and then a new heading and then show the last 10 fields.
      But only the fields which are filled.
      Is this possible?
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.