PC Review


Reply
Thread Tools Rate Thread

Dir Function Sanity Check

 
 
rjvega
Guest
Posts: n/a
 
      11th Jul 2008
Hi, I have a bit of code where the user enters a list of document numbers and
it goes out to a directory and copies the related PDF files to another
folder. It works fine, but I need it to go through one more check. Every
now and then, those who create the files sometimes have to create a second
file. For example, there may be a 5000064218.pdf AND a 5000064218 (2).pdf.

There is no way to tell without opening the PDF which one is the one they
will need, so what I want my code to do is see if there are multiples and
just identify those on the spreadsheet. The user will then have to manually
decide which file they need.

I created a check that seems to work, but I'm not sure if it will be a
robust test or if I just got lucky with the test. Here's what I have so far.

The document numbers are in column B and the source path and destination
path are in cells D2 and D4 respectively. n is just a counter that
increments the row. mdrow is the last row. tempa and tempb are just string
variables.

Do Until n = mdrow
srcfile = Range("D2").Value & "\" & Range("b" & n).Value
destfile = Range("D4").Value & "\" & Range("b" & n).Value & ".pdf"
tempa = (Dir(srcfile & "*"))
tempb = (Dir(srcfile & ".pdf"))
if tempa = tempb then
FileCopy srcfile, destfile
else
range("C" & n) = "Duplicate"
endif
n = n + 1
Loop

Now, with this code, tempb has been reading the (2) file if it exists and
the base file if no (2) exists. tempa is always reading the base file. So
it seems to be working, but I'm not sure if it will always work.

Thanks in advance.
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      11th Jul 2008
I am pretty sure what you have it robust but, based on your description of
what the file names look like, I would have done it slightly different
(saving a Dir call and the two temp variables in the process)...

Do Until n = mdrow
srcfile = Range("D2").Value & "\" & Range("b" & n).Value
destfile = Range("D4").Value & "\" & Range("b" & n).Value & ".pdf"
If Dir(srcfile & "*") Like "*(*)*" Then
Range("C" & n) = "Duplicate"
Else
FileCopy srcfile, destfile
End If
n = n + 1
Loop

Rick


"rjvega" <(E-Mail Removed)> wrote in message
news:0CFEFAFB-CED4-46EF-9AFA-(E-Mail Removed)...
> Hi, I have a bit of code where the user enters a list of document numbers
> and
> it goes out to a directory and copies the related PDF files to another
> folder. It works fine, but I need it to go through one more check. Every
> now and then, those who create the files sometimes have to create a second
> file. For example, there may be a 5000064218.pdf AND a 5000064218
> (2).pdf.
>
> There is no way to tell without opening the PDF which one is the one they
> will need, so what I want my code to do is see if there are multiples and
> just identify those on the spreadsheet. The user will then have to
> manually
> decide which file they need.
>
> I created a check that seems to work, but I'm not sure if it will be a
> robust test or if I just got lucky with the test. Here's what I have so
> far.
>
> The document numbers are in column B and the source path and destination
> path are in cells D2 and D4 respectively. n is just a counter that
> increments the row. mdrow is the last row. tempa and tempb are just
> string
> variables.
>
> Do Until n = mdrow
> srcfile = Range("D2").Value & "\" & Range("b" & n).Value
> destfile = Range("D4").Value & "\" & Range("b" & n).Value & ".pdf"
> tempa = (Dir(srcfile & "*"))
> tempb = (Dir(srcfile & ".pdf"))
> if tempa = tempb then
> FileCopy srcfile, destfile
> else
> range("C" & n) = "Duplicate"
> endif
> n = n + 1
> Loop
>
> Now, with this code, tempb has been reading the (2) file if it exists and
> the base file if no (2) exists. tempa is always reading the base file.
> So
> it seems to be working, but I'm not sure if it will always work.
>
> Thanks in advance.


 
Reply With Quote
 
rjvega
Guest
Posts: n/a
 
      11th Jul 2008
Thanks Rick.

There are occasional instances where they didn't name the file in the same
format and did a -2 or something like that. I know... we lack some
standards, but we're working on it!

"Rick Rothstein (MVP - VB)" wrote:

> I am pretty sure what you have it robust but, based on your description of
> what the file names look like, I would have done it slightly different
> (saving a Dir call and the two temp variables in the process)...
>
> Do Until n = mdrow
> srcfile = Range("D2").Value & "\" & Range("b" & n).Value
> destfile = Range("D4").Value & "\" & Range("b" & n).Value & ".pdf"
> If Dir(srcfile & "*") Like "*(*)*" Then
> Range("C" & n) = "Duplicate"
> Else
> FileCopy srcfile, destfile
> End If
> n = n + 1
> Loop
>
> Rick
>
>
> "rjvega" <(E-Mail Removed)> wrote in message
> news:0CFEFAFB-CED4-46EF-9AFA-(E-Mail Removed)...
> > Hi, I have a bit of code where the user enters a list of document numbers
> > and
> > it goes out to a directory and copies the related PDF files to another
> > folder. It works fine, but I need it to go through one more check. Every
> > now and then, those who create the files sometimes have to create a second
> > file. For example, there may be a 5000064218.pdf AND a 5000064218
> > (2).pdf.
> >
> > There is no way to tell without opening the PDF which one is the one they
> > will need, so what I want my code to do is see if there are multiples and
> > just identify those on the spreadsheet. The user will then have to
> > manually
> > decide which file they need.
> >
> > I created a check that seems to work, but I'm not sure if it will be a
> > robust test or if I just got lucky with the test. Here's what I have so
> > far.
> >
> > The document numbers are in column B and the source path and destination
> > path are in cells D2 and D4 respectively. n is just a counter that
> > increments the row. mdrow is the last row. tempa and tempb are just
> > string
> > variables.
> >
> > Do Until n = mdrow
> > srcfile = Range("D2").Value & "\" & Range("b" & n).Value
> > destfile = Range("D4").Value & "\" & Range("b" & n).Value & ".pdf"
> > tempa = (Dir(srcfile & "*"))
> > tempb = (Dir(srcfile & ".pdf"))
> > if tempa = tempb then
> > FileCopy srcfile, destfile
> > else
> > range("C" & n) = "Duplicate"
> > endif
> > n = n + 1
> > Loop
> >
> > Now, with this code, tempb has been reading the (2) file if it exists and
> > the base file if no (2) exists. tempa is always reading the base file.
> > So
> > it seems to be working, but I'm not sure if it will always work.
> >
> > Thanks in advance.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sanity check on call to imported DLL function Charles Calvert Microsoft C# .NET 4 12th Dec 2008 07:56 PM
Sanity check cypher_key Microsoft C# .NET 0 21st Sep 2007 12:33 AM
Sanity check Stephany Young Microsoft VB .NET 22 15th Feb 2007 11:29 PM
if end if sanity check... okrob Microsoft Excel Programming 5 5th Feb 2007 05:50 PM
Sanity check Richard Jones Anti-Virus 7 12th Apr 2004 01:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.