Start a New Discussion Ask a New Question

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I wrote a script to organize new PDFs into subfolders
  • Maybe someone will find this useful.

    I wrote a script for my company that creates a new folder with the Windows username, a subfolder with the date, and moves the newly created PDF file into that folder. (Example: "J:\PDFs\Joe\2010-04-26\Some document.PDF")

    It is useful for us because it automatically organizes all of the PDF's in one folder on a mounted network drive. PDFCreator is running locally with a copy of this script on each station, and not as a server. The username might not work the same if running in server mode. 

     

    ' MovetoUserDateFolder

    ' License: GPL

    ' Date: April 26, 2010

    ' Author: uhcafigdc

    <br />

    ' This script will -&nbsp;

    ' Create a new folder within the specified parent folder named by the Windows environment variable&nbsp;%USERNAME%

    ' Create a subfolder within that folder named by the current date yyyy-mm-dd

    ' Move the newly created PDF file into that folder

    <br />

    Option Explicit

    Const AppTitle = &quot;PDFCreator - Move to User Date folder&quot;

    Dim objArgs, objShell, objFolder, objFSO, wshShell, fname, parentfolder, newfolder, username

    <br />

    ' SET PARENT FOLDER HERE

    parentfolder = &quot;J:\PDF\&quot;

    <br />

    <br />

    Set objArgs = WScript.Arguments

    <br />

    If objArgs.Count = 0 Then

    &nbsp;MsgBox &quot;This script needs a parameter!&quot;, vbExclamation, AppTitle

    &nbsp;WScript.Quit

    End If

    <br />

    fname = objArgs(0)

    <br />

    <br />

    ' Get the username

    Set wshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)

    username = wshShell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)

    <br />

    ' Set the new folder name

    newfolder = username &amp; &quot;\&quot; &amp; DatePart(&quot;yyyy&quot;,Date) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; DatePart(&quot;m&quot;,Date), 2) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; DatePart(&quot;d&quot;,Date), 2)

    <br />

    ' Create the new folder

    Call CreateFolder(parentfolder, newfolder)

    Private Sub CreateFolder(pfolder, nfolder)

    <span class="Apple-tab-span" style="white-space:pre"> </span>set objShell = CreateObject(&quot;Shell.Application&quot;)

    <span class="Apple-tab-span" style="white-space:pre"> </span>set objFolder = objShell.NameSpace(pfolder)&nbsp;

    <span class="Apple-tab-span" style="white-space:pre"> </span>objFolder.NewFolder nfolder

    End Sub&nbsp;

    <br />

    ' Move the file to the new folder

    Call MovetoFolder(fname, parentfolder, newfolder)

    Private Sub MovetoFolder(file, pfolder, nfolder)

    <span class="Apple-tab-span" style="white-space:pre"> </span>Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

    <span class="Apple-tab-span" style="white-space:pre"> </span>objFSO.MoveFile file, pfolder &amp; nfolder &amp; &quot;\&quot;

    End Sub