PDA

View Full Version : check if file exists



saban
02-17-2006, 03:43 AM
Sub preimenujfajl()
Dim i As String 'doloci spremenljivko tipa string ki se bo nanasala na input box
Dim dat As FileSearch ' doloci spr. tipa filesearch(ki je objekt)
'Dim j As FileTypes 'mislim da to ne rabim
Title = "Vpi?i tip dokumenta in Fdr ?t."
i = InputBox(Title, "preimenuj bak in rtf", "Tu vpi?i tip dokumenta in Fdr ?t. in pritisni OK")
If StrPtr(i) = 0 Then

msgbox "Bak ni bil preimenovan ker je uporabnik kliknil Cancel"
Exit Sub
End If
'Set j = ".doc"
'Set dat = Application.FileSearch

'ActiveDocument.Close


With Application.FileSearch
.FileName = "luka.doc" & "luka.BAK"
.LookIn = "R:\"
.Execute
Name "R:\trados\tmpclean.rtf" As i & ".rtf"
Name "R:\trados\tmpclean.BAK" As i & ".BAK"

Dim prestav As String
prestav = i & ".doc"
Name i & ".rtf" As "R:\trados\BAK in RTF\" & i & ".rtf"
Name i & ".BAK" As "R:\trados\BAK in RTF\" & i & ".BAK"

Application.FileSearch.FileName = i
End With

End Sub

How can I do that when file is being renamed to check if that file already exists and to give user option to change the input box because when file already exists it just gives an error and that file that should be renamed is deleted and i dont wanna do that i just wanna rename it with other name

thnx

mark007
02-17-2006, 04:58 AM
You can check if a file exists using:


if dir(filename)="" then
'file does not exist
else
'file exists
end if


Therefore perhaps use a loop or maybe even a goto stetment to keep asking till a file that doesn't exist is specified.

You could also perhaps look into application.getsaveasfilename that will show a proper dialog box.

:)