Mag91

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

4 posts in this topic

#1 ·  Posted

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!

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

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

    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • Nareshm
      By Nareshm
      Hi All,
      I have excel file like this
      and i want to cut cell/text from excel to other software.

       
      I have to cut the cell of B column one by one and past into other software
      If Winexists("No Data Found")
      then restore cuted cell and goto next/down side cell
      How to do it ?
    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      ----
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      .....
      this numbers are a part of the filepath ...example
      D:\Projekte\1166_64233_5374
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
       
      --------
      Second question:
      If i am in the path.
      For Example:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      ----
      Please give me some help :-)
       
       
       
       
       
       
    • Skeletor
      By Skeletor
      Hi Guys,
      I've been reading this post ...
      When I came accross the examples, non of them had what I was looking for.
      I basically want to "snapshot" my GUI's multiple tabs and send them into the pdf.
      A little nudge from you guys would be great.
      Im really stuck with this one, therefore I have no code.
      Lets discuss or point me in a right direction... thanks alot