Check if a certain filename exists. If yes, next. If not, do somet

B

Brian Lukanic

What's the best way to determine if a specific filename on the server exists?
If it does exist, loop to next. (I am reading and parsing a CSV.) If not
exist, then save a file onto the the server with the filename as parsed from
the CSV.

My script below works great to create initial records. But my CSV file grows
with new additions mixed througout. I'd like my script to include
functionality that skips a record of the "filenametocreate" already exists on
the server.



Sub CreateClientRecords()

Dim sLayout, sTemp As String
Dim Value$, j As Integer

Open "C:\data\MyText2.txt" For Input As #2
Do While Not EOF(2)
Line Input #2, Value$

sTemp = Value$

sLayout = Split(sTemp, ",")

For j = 0 To UBound(sLayout)
s1 = sLayout(0)
s2 = sLayout(1)

' MsgBox sLayout(j)
Next j

'This is the project build phase
'FileOpenEx Name:="<>\zclient Workspace", ReadOnly:=False

' These commands fill in the required Project-level fields
ActiveProject.ProjectSummaryTask.SetField _
FieldNameToFieldConstant("Client ID"), s1

ActiveProject.ProjectSummaryTask.SetField _
FieldNameToFieldConstant("Zone"), s2

ActiveProject.ProjectSummaryTask.SetField _
FieldNameToFieldConstant("Portfolio Comments"), "Client Record created
by the loader."
FileSaveAs Name:="<>\Z-Client Workspace - " & s1, FormatID:=""
PauseIt 10
FileSave
PauseIt 5
Loop

Close 2
FileCloseEx pjSave, True, True

Dim sLayout2, sTemp2 As String
'Dim Value$, j As Integer

Open "C:\data\MyText2.txt" For Input As #2
Do While Not EOF(2)
Line Input #2, Value$

sTemp2 = Value$

sLayout2 = Split(sTemp2, ",")

For j = 0 To UBound(sLayout2)
s1 = sLayout2(0)
s2 = sLayout2(1)

' MsgBox sLayout2(j)
Next j

DisplayAlerts = False
FileOpenEx Name:="<>\Z-Client Workspace - " & s1, ReadOnly:=False
publish Republish:=Null, WssURL:="http://epm.csstarsit.com/PWA/" & s1
PauseIt 300
DisplayAlerts = True
FileCloseEx pjSave, True, True

PauseIt 10

Loop

Close 2

End Sub

Function PauseIt(NumOfSeconds As Integer) As Boolean

Dim dStart As Date

dStart = Now

Do
DoEvents
Loop Until DateAdd("s", NumOfSeconds, dStart) <= Now
End Function
 
R

Rod Gill

Hi the VBA command Dir(Path) returns the name if found and "" if not. This
is a very powerful command that you need to read help on to learn all its
uses.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
B

Brian Lukanic

Terrific I will start to research that. Sounds like it will indeed be powerful.

Thanks again Rod.
 
D

Dytham

I've used:

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("C:\WINNT\system32\filename.ext") Then
'do something
Else
'do something else
End If

Chas.
 
B

Brian Lukanic

But have you ever done this against Project Server? Any time I use the "<>\"
syntax as the directory location I run into errors.
 
R

Rod Gill

If you want to find a project in Project Server, the easiest way is to read
from the Reporting db the current list of published projects.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com




Brian Lukanic said:
But have you ever done this against Project Server? Any time I use the
"<>\"
syntax as the directory location I run into errors.



__________ Information from ESET Smart Security, version of virus
signature database 4468 (20090929) __________

The message was checked by ESET Smart Security.

http://www.eset.com

__________ Information from ESET Smart Security, version of virus signature database 4468 (20090929) __________

The message was checked by ESET Smart Security.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top