Jump to content

Recommended Posts

Posted

You're killing me.

Whatever path returned from FileListToArrayEx is a path to a pdf file, which you can't just execute.

First off you can't even use runwait here since you have to perform other actions inside Acrobat.

You must do it like this:

Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])oÝ÷ Ø    l¡«è×(ËZÙr­çÞ­éÜx4*Z¶Ø§²×u«­¢+ÙÉ¥Ù5Á ÅÕ½Ðí`èÅÕ½Ðì°ÅÕ½ÐìÀäÈìÀäÈí9å}ÌÄÀäÈí
½ÉÀÀäÈíɽÕÀÅÕ½Ðì¤

Put that at the top of your script and now any File or Folder open dialogs will show it as drive X

It doesn't work:

$MyArray=_FileListToArrayEx("\\Ny_fs1\Corp\Group","*.pdf",0,'',True)
MsgBox(0,"# files in $MyArray",$MyArray[0])
_ArrayDisplay($MyArray)

For i=1 to $MyArray[0]
;Run(@ComSpec & ' \c start "" "\\Ny_fs1\Corp\Group\' & $MyArray[$i] & '"',"",@SW_Hide)
    Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])
Next
  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted (edited)

It doesn't work:

$MyArray=_FileListToArrayEx("\\Ny_fs1\Corp\Group","*.pdf",0,'',True)
MsgBox(0,"# files in $MyArray",$MyArray[0])
_ArrayDisplay($MyArray)

For i=1 to $MyArray[0]
;Run(@ComSpec & ' \c start "" "\\Ny_fs1\Corp\Group\' & $MyArray[$i] & '"',"",@SW_Hide)
    Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])
Next
After any function that could potentially fail, you should always check @error to see if it worked.

Try this modification to your code:

$MyArray=_FileListToArrayEx("\\Ny_fs1\Corp\Group","*.pdf",0,'',True)
If NOT @error Then
  MsgBox(0,"# files in $MyArray",$MyArray[0])
  _ArrayDisplay($MyArray)

  For i=1 to $MyArray[0]
  ;Run(@ComSpec & ' \c start "" "\\Ny_fs1\Corp\Group\' & $MyArray[$i] & '"',"",@SW_Hide)
    Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])
  Next
Else
  MsgBox(16,"Error number "&@Error,"An error occured in _FileListToArrayEx - see the title of this message box to see the error number")
EndIf

Let us know what error you're getting, and we'll try to debug what's happening.

Edit: if it doesn't return an error, it could be this: I think that you need to provide the WHOLE path to the .pdf file to Acrobat by replacing

acrobat.exe " & $MyArray[$i])

with

acrobat.exe \\Ny_fs1\Corp\Group\" & $MyArray[$i])

Possibly, you could also set the working directory to \\Ny_fs1\Corp\Group in the Run command.

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Posted

The way it stands now nothing happens and the computer does not report errors. If I use the Run function as opposed to the line beneath it, at least notepad and the file open, but I cannot understand why FileOpen() doesn't do do that. I cannot tell why one would chose to use FileOpen instead of ShellExecute or Run . I also never see the array displayed, but the computer never notifies me of an error.

Look at the path you're asking it to FileOpen...it's in @ScriptDir, whereas when you open it in notepad, you're directing it to \\Ny_fs1\Corp\Group\ instead. Switch your FileOpen command to:

$handle = FileOpen("\\Ny_fs1\Corp\Group\\filesfound.txt", 0)oÝ÷ ٩ݱç¢~+p¢¹,Eè­Ø§«¨¶z-­ën®x§©Þ®º+ªê-¨º;¬¶gØZµ©²Æ yº1v¬m¦n¦Æ²x-êÞÁ«ê뢴ájÜ(mªizw¯zx¶«{¬jw«®îW¬²+wöÆjÖ¥zºè®j,µªÞmNrÛ²¶z'íêÞÁ«ê뢸¬¶!yÉ-ëÚç¨}ê뢻")Z®Úr¸©´8«¶§âµ«½ªâi¹^DLSaxX¥xê^Æ¥éÞÁ¬¨}Ú"aȬjëh×6$handle = FileOpen("\\Ny_fs1\Corp\Group\\filesfound.txt", 0)
If @error <> 0 Then; <> means not equal, in case you didn't know that
  MsgBox(16,"Error","Error number "&@error)
EndIfoÝ÷ Ù(¦V«Â+aªê-v¬m­ën®v¡jwez«¨´î²ÜÛh©²êÞʤ-«r¢èZ½ëhI3Ø^©Ýè§jö«¦åxò¢ìÛh±ç­èZÙ^¶§ºÇºÚ"µÍÌÍÔ[[OT[ÛÛTÜXÈ   [È ÌÎNÈØÈÝ   ][ÝÉ][ÝÈ    ][ÝÉÌÎNÉ[É][ÝÉÌLÉÌLÓWÙÌIÌLÐÛÜ ÌLÑÜÝ   ][ÝÉ[ÉÌÎNÉÌLÙ[ÙÝ[ ][ÝÉÌÎNË   ][ÝÉ][ÝËÕ×ÒQJBÙÐÞ
    ][ÝÉÌÍÔ[[H]X[Î][ÝË  ÌÍÔ[[J

Understand that in this case, the Run handle will be nearly useless, as it refers to the invisible command-line that is actually what causes notepad to run...the commandline closes as soon as notepad launches, so you won't be able to do anything with the stored $RunHandle...the window that it represented no longer exists!

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Posted (edited)

Sorry for another post...I can't edit without garbling it again.

I mis-typed the first bit in my previous post...there shouldn't be another double-backslash...the FileOpen command in both of the first two AutoIt code boxes should be:

$handle = FileOpen("\\Ny_fs1\Corp\Group\filesfound.txt", 0)oÝ÷ Ø l£*.q©æ¡ØË*.­§r¦jwm¡«­¢+Ø¡
½µMÁµÀìÌäì½ÍÑÉÐÅÕ½ÐìÅÕ½ÐìÅÕ½ÐìÀäÈìÀäÈí9å}ÌÄÀäÈí
½ÉÀÀäÈíɽÕÀÀäÈí¥±Í½Õ¹¹ÑáÐÅÕ½ÐìÌäì°ÅÕ½ÐìÅÕ½Ðì°M]}!%¤oÝ÷ Ø¥²j{m¡§]¶­#fjkzËw­Ø^r^Ê zw«j×~íç±z·"±â j÷²¢ì¨»oz·©ÉvêZwÜÚÌ®Ú*ºp,(ºWr¢ë¬xX¥xê^)ìµæ¡ôn«¨´X¥xê^ZËayø¥yú+yØ­x×+y«^±¬Éú+Ê«±Êâ¦ÛhD@¢µ!1-¢Ø^ríz{l¡ûayø¥x]¡ë
9:)zx­º§k§v(*.®Ç+yéÅW¥éèØ^·_W¢Øb±Æ¬zf«È­jȧºÇ¬¢ØZµ©è¶«ºÇ«þ趦¶¼¢h¢§¶W°Y[zÚ%v+wöÉhrGjwn²æ¥'^¥éÝx(Ø^¦º ­©¨}÷«j·våÊ÷«²*'¡ûayø¥xZÊ-zYlÊ«±Êâ¦Ûhëky§r¶h²¶§­ØZµø¥z·vð®+^¶­ºËèZÙ^+ÞúèØ^)^:§r¦jwb±¨ZÙ^Ê«±Êâ¦×ë¶që,¶W®Ø¥Ýý°X¥x)h±çZ¨§jÜ!Èmg­çâ謺yhrGj¢g·ö·®²)àJ¥L^rë^jwQº{hiËnjYrECZ=D'¢×©iÛajר¬¦V²¶¢{^Û(~Ø^~)^¢{­ç§æjYrq©eyÚ®¢Ú)zx§§âꮢÖÞq«¬zÚ+y§b´Ú-z§m¡Ú"¶Ê0÷«²*'¡ñbã©zr,¶­rW¬ú趦³br·P×Ú-)à³­ø¥zÇâëjvÞD@·ªº*Þ³*.¶ý¢§ßÛayø¥{^¶«Û!£(Ç+yéè®z-në_W¬q©÷öÖÞECX¢ç
j趦¶­ßÛzÈ çm ãÄ5§âæ§uÚ-)à³­+eGÊek(­¢{azÇ+yéí br¬Â­-¥ê)ëay(}«*ºh¥éâ
®¢Ú+ªê-®éçx*ºZ~)^Ƨ{¦¦W«º{aË®*mjëh×6$TheFile=FileOpen(@ScriptDir&"\example.txt",2)
$Timer=TimerInit()
Do
  sleep(100)
Until TimerDiff($Timer) > 30000
FileClose($TheFile)
MsgBox(0,"Done","File is closed")

While that script is running, go to the folder it's in, and you'll see a document called example.txt. Try to delete it. Windows won't let you because a program (your script) has that file opened (locked)! So it's OPEN in the program, but your program isn't designed to display that file or even to write to it. A program can do anything or nothing with a file it's opened...it just means it's locked for exclusive use by that program...whatever use that program is designed to do.

Wait 30 seconds for the program to end. The file is closed, and now you can delete it.

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Posted

The computer complains that this for loop is badly formated:

For i=1 to $MyArray[0]
 ;Run(@ComSpec & ' \c start "" "\\Ny_fs1\Corp\Group\' & $MyArray[$i] & '"',"",@SW_Hide)
    Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])
  Next
Posted

The computer complains that this for loop is badly formated:

For i=1 to $MyArray[0]
;Run(@ComSpec & ' \c start "" "\\Ny_fs1\Corp\Group\' & $MyArray[$i] & '"',"",@SW_Hide)
    Run(@ProgramFilesDir & "\Adobe\Acrobat 6.0\Acrobat\acrobat.exe " & $MyArray[$i])
  Next
It's possible that $MyArray isn't an array because the _FileListToArrayEx() function failed. Since it's not an array if this is the case, $MyArray[0] doesn't exist and is invalid.

To prevent this, you should check the value of @error after calling the function to make sure it worked (@error is 0 if it worked). This is called doing 'error checking' and is a very good practice after almost any function that has a possibility of failing. Some other ways of checking if it failed: if you check UBound($MyArray) after _FileListToArrayEx() fails, it will return 0 and set @error to 1. Also, since it's not an array, IsArray($MyArray) will return 0 if _FileListToArrayEx() failed. If any of these checks tell you it might have failed, you need to do something else (exit, throw an error messagebox then exit, prompt for another location to try...anything but your For loop).

That will make sure that when your script gets down to your For loop, $MyArray is a valid array.

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Posted (edited)

New version, fully idiot proofed (up till acrobat executes)

It will attempt drive mapping for you, and report any errors creating file array

#include <FileListToArrayEX.au3>
#include <Array.au3>

;Match exact window titles
Opt("WinTitleMatchMode", 3)

$ACROBAT = "Adobe Acrobat Standard"
$REDUCE = "Reduce File Size"
$SAVEAS = "Save As"

;Map source folder
TrayTip ( "Mapping...", "Attempting drive mapping...be patient",30 )

$MAP = DriveMapAdd ( "X:", "\\Ny_fs1\Corp\Group\" )

If $MAP = 0 Then 
    MsgBox(0,"","Drive mapping failed") 
EndIf

$PDFINPUT = FileSelectFolder ( "PDF Source", "",7 )
;$PDFINPUT = @ScriptDir & "\IN"

$PDFOUTPUT = FileSelectFolder ( "PDF Destination", "",7 )
;$PDFOUTPUT = @ScriptDir & "\OUT"

;Make sure source and destination differ
If $PDFOUTPUT = $PDFINPUT Then
    MsgBox(0,"","Source and destination cannot be the same")
EndIf

$PDFLIST = _FileListToArrayEx($PDFINPUT, '*.pdf', 1,'', True)

;Check returned errors from _FileListToArrayEx
Switch @ERROR
    Case 1
        MsgBox(0,"","Path not found or invalid")
        Exit
    Case 2
        MsgBox(0,"","Invalid $sFilter or Invalid $sExclude")
        Exit
    Case 3
        MsgBox(0,"","Invalid $iFlag")
        Exit
    Case 4
        MsgBox(0,"","No File(s) Found")
        Exit
EndSwitch

;Check for errors creating file list
If ($PDFLIST = 0 OR IsArray ($PDFLIST) = 0) Then
    MsgBox(0,"","Error encountered while creating file array, Exiting")
    Exit
EndIf

;For $X = 1 to 1
For $X = 1 to $PDFLIST[0]
    ;Force new instance of Acrobat - CAREFUL THIS WILL LAUNCH A NEW INSTANCE FOR EVERY FILE
    ;Run(@ProgramFilesDir & "\Adobe\Acrobat 7.0\Acrobat\acrobat.exe /n " & @ScriptDir & "\" & $PDFINPUT & "\" & $PDFLIST[$X])
    
    ;Break file path into array
    $A = StringSplit($PDFLIST[$X], "\")
    
    ;Strip filename from file path
    $FILENAME = _ArrayPop ($A)
    
    ;Compact array, replace input folder with output
    $DIR = StringReplace ( _ArrayToString ( $A, "\",1 ), $PDFINPUT, $PDFOUTPUT)
    
    ;Create folder structure
    DirCreate ( $DIR )
    
    ;Delete file, otherwise Acrobat will prompt for file delete
    FileDelete($DIR & "\" & $FILENAME)
    
    ;Open file in Acrobat 7
    Run(@ProgramFilesDir & "\Adobe\Acrobat 7.0\Acrobat\acrobat.exe " & $PDFLIST[$X])
    WinActivate (StringFormat("%s - [%s]",$ACROBAT,$FILENAME))
    WinWaitActive (StringFormat("%s - [%s]",$ACROBAT,$FILENAME))
    
    ;Send Alt-F to open file menu
    Send ( "!f" )
    
    ;Send z to open Reduce File Size
    Send ( "z" )
    
    WinActivate ($REDUCE)
    WinWaitActive ($REDUCE)
    
    ;Click OK Button, leaving Acrobat 7 as default output
    ControlClick ($REDUCE, "","[CLASS:Button; INSTANCE:2]" )
    
    WinActivate ($SAVEAS)
    WinWaitActive ($SAVEAS)
    
    ;Set file path to output folder with same filename
    ControlSetText($SAVEAS, "", "[CLASS:Edit; INSTANCE:1]" , $DIR & "\" & $FILENAME)
    
    ;Click save
    ControlClick ($SAVEAS, "","[CLASS:Button; INSTANCE:2]" )
    
    ;Reactivate main window
    WinActivate (StringFormat("%s - [%s]",$ACROBAT,$FILENAME))
    WinWaitActive (StringFormat("%s - [%s]",$ACROBAT,$FILENAME))
    
    ;Send CTRL-W to close file
    Send ( "^w" )
    
    ;Wait for Acrobat title to eliminate file name before continuing
    WinWaitActive ($ACROBAT)
Next
Edited by weaponx
Posted

Maybe a user name and password are required, this flag will prompt for both if they are needed:

$MAP = DriveMapAdd ( "X:", "\\Ny_fs1\Corp\Group\",8 )

Or is that drive letter in use? Maybe you need admin rights to add map?

Posted (edited)

It's possible that $MyArray isn't an array because the _FileListToArrayEx() function failed. Since it's not an array if this is the case, $MyArray[0] doesn't exist and is invalid.

To prevent this, you should check the value of @error after calling the function to make sure it worked (@error is 0 if it worked). This is called doing 'error checking' and is a very good practice after almost any function that has a possibility of failing. Some other ways of checking if it failed: if you check UBound($MyArray) after _FileListToArrayEx() fails, it will return 0 and set @error to 1. Also, since it's not an array, IsArray($MyArray) will return 0 if _FileListToArrayEx() failed. If any of these checks tell you it might have failed, you need to do something else (exit, throw an error messagebox then exit, prompt for another location to try...anything but your For loop).

That will make sure that when your script gets down to your For loop, $MyArray is a valid array.

But doesn't the long list of files that I get from _ArrayDisplay($MyArray) prove that $MyArray is an array?

Anyway I used the code below to check to see if $MyArray is an array and it was:

$errchecker=IsArray($MyArray)
If $errchecker=0 Then 
    MsgBox(0, "_FilesListToArrayEx Error", "$MyArray is not array")
EndIf

If NOT @error Then
  MsgBox(0,"# files in $MyArray",$MyArray[0])
  _ArrayDisplay($MyArray)

The Run part of the script still doesn't work though.

Edited by ConstantineGeorgantzas
Posted

Maybe a user name and password are required, this flag will prompt for both if they are needed:

$MAP = DriveMapAdd ( "X:", "\\Ny_fs1\Corp\Group\",8 )

The drive mapping still fails and I am not prompted for either.

Or is that drive letter in use? Maybe you need admin rights to add map?

I cannot answer that. Who can?
Posted

The drive mapping still fails and I am not prompted for either.

I cannot answer that. Who can?

I just tested the mapping to a share on my network and it worked fine. The second time I ran the script the drive was already mapped so an error was shown, this is normal. The process still completed successfully.

I also even tried hardcoding a UNC path, find this code and modify accordingly. This worked successfully as well.

;$PDFINPUT = FileSelectFolder ( "PDF Source", "",7 )
;$PDFINPUT = @ScriptDir & "\IN"
$PDFINPUT = "\\WSOS_APPS\USER\USERS\XXXXXX\IN"
Posted (edited)

I just tested the mapping to a share on my network and it worked fine. The second time I ran the script the drive was already mapped so an error was shown, this is normal. The process still completed successfully.

This is what is probably happening in my case. I'll keep testing.

Now I get an error from _FileToFolderEx: "No Files Found."

Edited by ConstantineGeorgantzas
Posted

This is what is probably happening in my case. I'll keep testing.

Now I get an error from _FileToFolderEx: "No Files Found."

That UNC path can't be correct.

Try mapping it manually through windows.

Start > Run > cmd.exe

net use

This will show your current mappings, is that path in there?

net use X: \\Ny_fs1\Corp\Group\

Do you get an error?

If you don't get an error go to My Computer and open up drive X:, do you see anything?

Posted

"Try mapping it manually through windows. Start > Run > cmd.exe" - How do I do that

I gave you the instructions man.

Click Start

Click Run

Type cmd.exe

Hit Enter

Type net use

Hit Enter

This is a list of active mappings.

Type net use X: \\Ny_fs1\Corp\Group\

Hit Enter

If it works look for drive X: in my computer. Not rocket science.

Posted (edited)

I gave you the instructions man.

Click Start

Click Run

Type cmd.exe

Hit Enter

Type net use

Hit Enter

This is a list of active mappings.

Type net use X: \\Ny_fs1\Corp\Group\

Hit Enter

If it works look for drive X: in my computer. Not rocket science.

X: \\Ny_fs1\Corp\Group\ was in the list of active mappings, but the commands you gave me didn't work and the drive is not under My Computer. The error reported was error 67.

Edited by ConstantineGeorgantzas
Posted

Error 67 means the UNC path is invalid. If it's not showing in my computer you have other problems. Where is your network admin?

If you open up My Network Places you should be able top find the resource Ny_fs1

If you open it you should see Corp, open it

If you see a folder called Group, right click on it and click Map Network Drive

Posted

Error 67 means the UNC path is invalid. If it's not showing in my computer you have other problems. Where is your network admin?

If you open up My Network Places you should be able top find the resource Ny_fs1

If you open it you should see Corp, open it

If you see a folder called Group, right click on it and click Map Network Drive

I followed your directions, but Map Network Drive is not an option that comes up when I right click the GROUP folder.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...