Powershell Script to list pdf files in a directory

Hey Scripting guy, I read few of your forum solutions for the scripts and was really enthralled to embrace this powershell scripting, thanks for the motivation.
I am still a learner and want to learn more, I had to do a script on generating an excel report which consisted of number of files of files in PDF format for each directory and sub-directory in the path.
I used the,
get-childitem $Path -recurse | where {$_.Extension -match "pdf"}
command, all I wanted to know is how to count the number of PDF files in each sub directory, please help me out,
Thanks in advance

Ok, let's have some fun :)
function Count-FilesRecursive{
Param(
[parameter(Mandatory = $true, Position = 0)]
[string]$Path,
[parameter(Mandatory = $true, Position = 1)]
[string]$Filter
$SB_recursive = {
[System.IO.Directory]::GetDirectories($args[0])|ForEach-Object {
Try{
$i = ([System.IO.Directory]::GetFiles($_,$Filter)).Count
Catch [UnauthorizedAccessException] {
$i = 0
"{0,-10} {1}" -f $i, $_
Try{
$SB_recursive.Invoke($_)
Catch [UnauthorizedAccessException] {}
"{0,-10} {1}" -f "Number of files", "Path"
"{0,-10} {1}" -f "---------------", "----"
$SB_recursive.Invoke($Path)
Count-FilesRecursive -Path C:\users -Filter '*.pdf'

Similar Messages

  • Script to resize pdf-files by percentage

    Dear all,
    I have a rather simple problem: I need to resize a collection of several pdf files (around 60) by a certain percentage, because those files are included in a text (LaTex) - and I need to change the LaTex page style (in other words: the layout) - so that my old images are all a bit too large for the layout; thus I want to do a quick-and-dirty solution and resize them all by a certain percentage (defined by the difference between my old layout and the new, more slim one).
    So - the simple question is: does anyone know either if there is simple free software out there that can do this (I didn't find any - and Acrobat 9 doesn't offer the possibility to change the dimensions of pdf images) - or, b) if this would be possible to do with Applescript? Off course, I wouldn't mind a ready-made script - but, since I don't know, but want to learn Applescript, I thought that this might be a good task to start with - although I also need a solution in 3 to 4 days - hope it wouldn't be a too frustrating task to start with...
    Thanks for any hints!
    With kind regards,
    Björn
    Message was edited by: bBcuda

    Hello
    You might try something like the following script.
    It will a) resize the pdf image by using Image Events and save it as png and b) convert png to pdf by png2pdf.
    You'd need to have png2pdf installed in advance.
    (Image Events can open pdf but cannot save as pdf according to the document.)
    The script will let you choose source folder where original pdfs reside and destination folder where modified pdfs are to be stored. Also it will let you specify scaling factor. After that it will open each pdf file (*.pdf) in source folder, resize and save as new png file in destination and then convert the png to pdf (and delete png if successful). Hopefully it's like that.
    Script is NOT tested and I don't know how good (or bad) Image Events and png2pdf are, for I don't use OSX for myself. Sorry about that.
    Good luck,
    H
    --SCRIPT (NOT TESTED)
    Using Image Events and png2pdf
    Image Events
    http://www.apple.com/applescript/imageevents/
    http://www.apple.com/applescript/imageevents/04.html
    http://www.apple.com/applescript/imageevents/08.html
    png2pdf
    http://png2pdf.sourceforge.net/
    http://png2pdf.sourceforge.net/png2pdf.pdf
    main()
    on main()
    script o
    property scaling_factor : 0.8 -- default scaling factor
    property remove_png : true -- whether remove intermediate png files or not
    property nn : {} -- working list
    --(0) preparation
    -- (0.1) set input and output directories (= ind, indp, outd, outdp)
    set ind to choose folder with prompt "Choose source folder."
    set outd to choose folder with prompt "Choose destination folder."
    set indp to ind as Unicode text
    set outdp to outd as Unicode text
    -- (0.2) set scaling factor (= r)
    set r0 to scaling_factor as string -- default scaling factor as string
    repeat
    display dialog "Enter scaling factor." default answer r0 with icon 1
    try
    set r to text returned of result as real
    exit repeat
    on error --
    end try
    end repeat
    -- (1) process each pdf file in input directory
    set nn to list folder ind without invisibles -- get item names
    repeat with n in my nn
    set n to n's contents
    if n ends with ".pdf" then -- only process "*.pdf"
    -- (1.1) open pdf, resize and save it as new png file
    set infp to indp & n
    set outfp to outdp & n's text 1 thru -4 & "png" -- set output path
    tell application "Image Events"
    set p to open (infp as alias)
    scale p by factor r
    save p as PNG in file outfp
    close p
    end tell
    -- (1.2) convert png to pdf (and optionally remove png if successful)
    set infpx to quoted form of POSIX path of (outfp as alias)
    set outfpx to quoted form of ((POSIX path of outd) & n)
    if remove_png then
    do shell script ("png2pdf -p1.4 -n -a " & infpx & " " & outfpx & " && rm -f " & infpx)
    else
    do shell script ("png2pdf -p1.4 -n -a " & infpx & " " & outfpx)
    end if
    end if
    end repeat
    -- (2) decent notice
    display dialog "Done." with icon 1 giving up after 5
    end script
    tell o to run
    end main
    --END OF SCRIPT
    Message was edited by: Hiroto (fixed typo)

  • PowerShell script to list ALL documents bigger than 10MB - in list attachments/libraries all over my site?

    Hi there,
    Just wondering if someone can give me the PowerShell script to list ALL documents bigger than 10MB - in list attachments/libraries all over my site?
    Really appreciated.
    Thank you.

    Hello,
    here you can find sample to help you create yoru script :
    http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts
    see this sample extract from this site
    Get-SPWeb http://sharepoint/sites/training |
                                     Select -ExpandProperty Lists |
                                     Where { $_.GetType().Name -eq "SPDocumentLibrary" -and
                                             -not $_.Hidden }
    |
                                     Select -ExpandProperty Items |
                                     Where { $_.File.Length -gt 5000 } |
                                     Select Name, {$_.File.Length},
                                            @{Name="URL";
                                            Expression={$_.ParentList.ParentWeb.Url
    + "/" + $_.Url}}
    this can help too :
    https://gallery.technet.microsoft.com/office/Get-detail-report-of-all-b29ea8e2
    Best regards, Christopher.
    Blog |
    Mail
    Please remember to click "Mark As Answer" if a post solves your problem or
    "Vote As Helpful" if it was useful.
    Why mark as answer?

  • How to download the script data into pdf file

    how to download the script data into pdf file
    i have one option to download the script data to pdf file --->rstxpdft4 program.
    i have one doubt how to use this proogram.or any function module to download the script data to pdf file.
    Thanks and regards,
    Sri.

    Hi      Sri Sai,
    I know one method to convert the sapscript to pdf file :
    first generate a Spool Request for the required Sapscript
    then goto transaction SP01 and copy the generated Spool Request number
    now execute the SAP report RSTXPDFT4
    here enter the copied Spool request number and the target directory into the parameters
    execute the report
    required pdf file will be generated into the target directory
    i hope it will help you out
    Please refer this simple program:
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    Reward points if found helpful....
    Cheers,
    Eshwar.

  • How can I perform the conversion of pdf files in Cyrillic script to Word files in Cyrillic script. The pdf file is too small for me to read right now. Julyan Watts

    How can I perform the conversion of .pdf files in Cyrillic script to Word files in Cyrillic script. The .pdf file is too small for me to read without a magnifying glass, and the document is more than one thousand pages.

    This answer was not helpful. First of all, I could not find "tech specs"
    anywhere on the Acrobat 11 homepage. And secondly I purchased this software
    for the specific purpose of converting .pdf files to Word. It was only
    after I had completed the purchase that I learnt that Acrobat does not
    permit the conversion of .pdf files in Cyrillic to Word files  in Cyrillic.
    I feel that Acrobat should have provided this crucial information before I
    allowed my credit card to be debited. That is why I  am now asking for my
    money back. But thanks for your attempt to solve my problem, even if it was
    not successful.
    Julyan Watts

  • How to create pdf files in UNIX directory from oracle reports

    I would like to know how to create pdf files in UNIX directory from oracle reports.
    Thanks,

    Please make your question more clear . Also mention the reports version.
    1) If you are runnning reports in Unix, you can give
    .... destype=file desformat=pdf desname=<filename>
    in command line
    Please refer docs below.
    2) If by your question you mean
    "My reports server is running in Windows but I want to ftp my files to Unix after creating it"
    then the answer is that you can use pluggable destination "ftp"
    .... destype=ftp desformat=pdf desname=<ftp url>
    Pluggable destinations download
    http://otn.oracle.com/products/reports/pluginxchange/index.html
    Thanks
    Ratheesh
    [    All Docs     ]
    http://otn.oracle.com/documentation/reports.html
    [     Publishing reports to web  - 10G  ]
    http://download.oracle.com/docs/html/B10314_01/toc.htm (html)
    http://download.oracle.com/docs/pdf/B10314_01.pdf (pdf)
    [   Building reports  - 10G ]
    http://download.oracle.com/docs/pdf/B10602_01.pdf (pdf)
    http://download.oracle.com/docs/html/B10602_01/toc.htm (html)
    [   Forms Reports Integration whitepaper  9i ]
    http://otn.oracle.com/products/forms/pdf/frm9isrw9i.pdf

  • How to list the files in a directory which are recently modififed few mins

    Hi,
    I need command to list the files in a directory which are modified few minutes ago in SunOS. like "find . -cmin 2 -print " which list files that are modified 2 mins ago in Linux platform.
    Thanks in advance.
    sudha85

    The find command that comes with solaris doesnt have the cmin operator. Only mtime whose option is days.
    So install gnu find from sunfreeware which is the same one that comes with linux.

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • I want read PDF file from SAP directory and create a spool request or print

    Hi all,
    I want read PDF file from SAP directory and create a spool request or print the pdf through SAP. Can any body  help me in this.
    Also please write to me if its possible to open PDF from SAP directory to adobe pdf reader.
    Thanks in advance,
    Sunny

    Hi Sunny,
    Check these links.
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    http://www.erpgenie.com/sap/abap/pdf_creation.htm
    http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
    http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp
    http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • List of Files in a directory

    Is there a way that you can get a list of files in a directory that are spelt a certain way? Ex. If in a directory there are html files, txt files, et, In java can I get *.html or a html file with certain text in the name? java.html??
    How you can Help
    US101

    here are the code to list your files
         File startDir = new File("your directory goes here" );
         File[] dirList = startDir.listFiles();
         if (startDir.isDirectory());
         out.print( startDir.getPath() );
              //Start cycling through the array for the file
         for ( int count = 0; count < dirList.length; count++ )
    String fileName = dirList[count].getName();
              int index = fileName.lastIndexOf('.');
              String newString = null;
                   if (index >= 0)
                        newString = fileName.substring(index, fileName.length());
                        if ( newString.equalsIgnoreCase( ".txt"))
                             if ( dirList[count].isDirectory())
                                  out.println( dirList[count].getName() );
                             else
                                  out.println( dirList[count].getName());
                             }//end else
                        }// end if newstring
         }//end if index
         }//end for

  • How do I mass protect about 200 pdf files in a directory without opening them individually?

    How do I mass protect about 200 pdf files in a directory without opening them individually? I have Adobe Acrobat X Pro.
    They can all have the same password.
    Any ideas?

    If they can all have the same password, just make 200 copies of the protected file in your operating system...
    Edit: I think I misread your initial post. If the files are not identical, you can use an Action to encrypt all files using the same password.

  • Getting the list of  files in a directory by their last modified date

    Dear friends,
    I want to get the list of files in a directory sorted by their last modified date.
    By default the file.list() or listFiles() return files sorted by their name in ascending order.
    Please give me your suggestions.
    Thanks in advance,
    James.

    Thanks friend,
    I myself got the answer
    here is my code:
    public File[] getSortedFileList(File dir){
    File[] originalList = dir.listFiles();
    int numberOfFiles = originalList.length;
    File[] sortedList = new File[numberOfFiles];
    long[] lastModified = new long[numberOfFiles];
    for(int i = 0; i < numberOfFiles; i++){
    lastModified[i] = originalList.lastModified();
    Arrays.sort(lastModified);
    for(int i = 0; i < numberOfFiles; i++){
    for(int k = 0; k < numberOfFiles; k++){
    if(originalList[k].lastModified() == lastModified[i])
    sortedList[i] = originalList[k];
    System.out.println("The sorted file list is:" + sortedList[i]);
    return sortedList;

  • Power shell script to list all files and folder permissions recursively

    Hi All,
    I am looking for a powershell script to perform the following operations.
    1) To list the folder and file permissions(Allow,Deny both) recursively in a given folder.
    2) List out all the files and folders which are having the deny permission or having only the read access (or) only the write access. Basically the folder should have Read,Execute,Write permissions. Else we have to flag that file/folder name.
    I had written a batch script for the same which does this task using icacls.exe output, but this script takes lot of time to recursively parse all the files ( ~1 lakh files).
    Please help me with the powershell script for the same.
    Thanks
    Sambasiva

    Try this module: http://gallery.technet.microsoft.com/scriptcenter/PowerShellAccessControl-d3be7b83
    After importing the module, you can run something like this:
    dir c:\folder -recurse | Get-AccessControlEntry
    That output can be exported to a CSV for later viewing. You can also provide some parameters to Get-AccessControlEntry to limit the results:
    dir c:\folder -recurse | Get-AccessControlEntry -FileRights Write
    dir c:\folder -recurse | Get-AccessControlEntry -AceType AccessDenied
    dir c:\folder -recurse | Get-AccessControlEntry -AceType AccessAllowed -FileRights Write

  • Script for Place PDF file into a InDesign file

    Hi everyone, i need to import a PDF file into a InDesign document and in order to do this i used scripts found over  the net (e.g. Zanelli's script ecc.) but i tried this solution:
    function(){
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
        var myDocument, myPage;
        if(app.documents.length != 0){
            myDocument = app.activeDocument;
        else{
            alert("No document opened");
            exit();
         if (app.selection[0] == undefined) {
            alert("Select box");
            exit();
         } else {
                var myPDFFile = File.openDialog("Select PDF:");
                if((myPDFFile != "")&&(myPDFFile != null)){
                    myDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;   
                    var myData = new Array;
                    myData[0] = app.selection[0].parentPage;
                    myData[1] = app.selection[0].geometricBounds;
                    myData[2] = app.selection[0];
                    myPlacePDF(myDocument, myData, myPDFFile);
        //FUNCTIONS
        function myPlacePDF(myDocument, myData, myPDFFile){
            var myPDFPage;
            var myPage = myData[0];
            var myGeometricBounds = myData[1].toString().split(",");
            app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
            var myCounter = 1;
            var myBreak = false;
            while(myBreak == false){
                if(myCounter > 1){
                    myPage = myDocument.pages.add(LocationOptions.after, myPage);
                 app.pdfPlacePreferences.pageNumber = myCounter;
                 myRectangle = myPage.rectangles.add(undefined, undefined, undefined, {geometricBounds:[myGeometricBounds[0],myGeometricBounds[1],myGeometricBounds[2],myGeometricBounds[3]]});
                 myRectangle.clearFrameFittingOptions();  
                 myRectangle.frameFittingOptions.fittingOnEmptyFrame = EmptyFrameFittingOptions.PROPORTIONALLY;
                 myRectangle.frameFittingOptions.autoFit = true;
                 myRectangle.frameFittingOptions.fittingAlignment = AnchorPoint.CENTER_ANCHOR;
                 myPDFPage = myRectangle.place(File(myPDFFile), false)[0];           
                 if(myCounter == 1){
                    var myFirstPage = myPDFPage.pdfAttributes.pageNumber;
                else{
                    if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){
                        myPage.remove();
                        myBreak = true;
                myCounter = myCounter + 1;
             myData[2].remove();  
    what i would is, before the script place every single page of PDF file in the document, determine if the same page of the Pdf file is vertical or horizontal, to make the right section for the page.
    Is it possible?
    Thank you

    Moved to scripting forum...

  • Script to Split PDF files on Bookmarks

    I'm totally new to Java scripting.  What I'm looking for is a script I can run from batch processing with professional that will look at a collection files in s directory and split ech one of them on their bookmarks into smaller files.
    The bookmarks are all based on the page so it is possible to use the bookmark object's "execute" method to execute the bookmark action and pickup the page number.
    I read that last part somewhere. If someone can give me a reference to a thread or just some code to get me started that would help. Thanks,
    Josh

    5 years later... hopefully this helps someone out there.
    I couldn't find much information online about this myself, but hammered away until it worked. My code is for a slightly different purpose, but you should easily be able to adjust it for your needs.
    My sources:
    Adobe IAC Developer Guide
    Adobe IAC API Reference
    Adobe JS API Reference
    Adobe Acrobat and VBA – An Introduction | Karl Heinz Kremer's Ramblings
    UtterAccess Discussion Forums > Splitting Pdf Files
    Private Sub extractBookmark()
    Dim AcroApp As AcroApp, AVDoc As AcroAVDoc, PDDoc As AcroPDDoc, PDBookmark As AcroPDBookmark, AVPageView As AcroAVPageView
    Dim newPDF As AcroPDDoc, mergePDF As AcroPDDoc
    Dim jso As Object, BookMarkRoot As Object
    Dim masterPath As String, testName As String, i As Variant, bookmark As Variant
    Dim startN As Integer, endN As Integer, nPages As Integer, totalP As Integer
    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    Set PDDoc = CreateObject("AcroExch.PDDoc")
    Set PDBookmark = CreateObject("AcroExch.PDBookmark")
    masterPath = ActiveWorkbook.Path & "\MasterDocument.pdf"     'Path of the PDF containing the bookmarks to be extracted
    AVDoc.Open masterPath, vbNull
    Set AVPageView = AVDoc.GetAVPageView
    Set PDDoc = AVDoc.GetPDDoc
    Set jso = PDDoc.GetJSObject
    Set BookMarkRoot = jso.BookMarkRoot
    bookmark = jso.BookMarkRoot.Children
    totalP = PDDoc.GetNumPages
    'Loop through the 10 bookmarks in MasterDocument.pdf and get the starting page # of each. This # has to be changed to the # of bookmarks in your pdf. Or write something to count the bookmarks and use that variable. "productName" is a global variable for my specific project... You'll need to revise this for your purpose.
    For i = 0 To 9
        If bookmark(i).Name = productName Then
            PDBookmark.GetByTitle PDDoc, bookmark(i).Name
            PDBookmark.Perform AVDoc
            AcroApp.Exit
            startN = AVPageView.GetPageNum
            If i < 9 Then
                PDBookmark.GetByTitle PDDoc, bookmark(i + 1).Name
                PDBookmark.Perform AVDoc
                AcroApp.Exit
                endN = AVPageView.GetPageNum
                nPages = endN - startN
            Else
                nPages = totalP - startN
            End If
        End If
    Next
    PDDoc.Close
    'This part will also need to be modified. I am inserting the bookmarks into an already made PDF (global variable for me "fName"). You'll want to create a new pdf.
    Set newPDF = CreateObject("AcroExch.PDDoc")
    Set mergePDF = CreateObject("AcroExch.PDDoc")
    newPDF.Open fName & ".pdf"     'This line needs changing for your purpose. Probably could be.... newPDF.Create
    mergePDF.Open masterPath
    newPDF.InsertPages 0, mergePDF, startN, nPages, 0
    newPDF.Save PDSaveFull, fName & ".pdf"
    newPDF.Close
    mergePDF.Close
    End Sub

Maybe you are looking for