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

#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

    • Iznogoud
      By Iznogoud
      Hi,
      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?
    • mLipok
      By mLipok
      Here:
      https://github.com/nachbar/TRichViewToPdfUsingDebenu/blob/master/Unit1.cpp
      I found a code in C++ for file format conversion from RTF to PDF with using Debenu QuickPDF.
      I know how to use Debenu QuickPDF in AutoIt .
      My question is about RTF part of this code:
       
      HDC hdcNew = debenu->GetCanvasDC( RTFPRINTINGDOTSPERINCH * RTFPAGEWIDTHININCHES, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight);  
      First there is hdcNew declaration , and this is not the problem.
      My problem is in converting the following code snippet, to AutoIt
      canvas = new TCanvas; canvas->Handle = hdcNew; RVReportHelper1->DrawPage( PageCounter, canvas, true, RTFPRINTINGDOTSPERINCH * RTFPAGEHEIGHTININCHES); // LastPageHeight);
      If you remember, I created RTFPrinter sometime ago. But it was some time ago , and created by trial and error, rather than in-depth analysis.
      Also, it was just a modification of another script, not my own work from scratch.
      So now I'm looking for help how to adapt this code snippet to AutoIt.
      Any tips ?
       
      Regards,
      mLIpok
       
    • Kiran_L
      By Kiran_L
      Hi guys,
       
      I am trying to read a pdf file with unstructured data. I dontot know how to handle pdf activities in AutoIt,
      Can you help me with any UDF to open the PDF and read the doc.
       
      Thanks for your time.
       
    • 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