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

 

THANKS!

 

Link to comment
Share on other sites

  • Developers
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.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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)
Send("{CTRLDOWN}v{CTRLUP}")

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)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

Func STOP()
While 1
Sleep(120)
WEnd
EndFunc

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

        Case $Button1 ;Start

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

If ProcessExists ("EXCEL.EXE") Then
    WinActivate ("BigBag_ab_31.01.17.xlsx - Excel")
    EndIf
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)
Send("{CTRLDOWN}v{CTRLUP}")




EndSwitch
WEnd

 

 

Link to comment
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)
        Exit
    EndIf
EndIf

;===========================================================================================
; 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
    _Excel_BookClose($oExcel)
    _Excel_Close($oExcel)

    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!!!")
        Exit
    Else
        Local $aFileList = _FileListToArray($pathtopdfs, "*.pdf")
        If @error = 1 Then
            MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
            Exit
        EndIf
        If @error = 4 Then
            MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
            Exit
        EndIf

        ;===========================================================================================
        ; 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)
        Next
    EndIf

EndIf

Welcome to the Autoit comunity :bye:

 

Greets from Barcelona

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

×
×
  • Create New...