Home > Software engineering >  How to determine the INI file exists, does not exist, how to generate this file
How to determine the INI file exists, does not exist, how to generate this file

Time:10-11

How to determine the INI file exists, does not exist, how to generate this file

CodePudding user response:

 If Len (Dir (" ini files. Ini "))=0 Then 
Open "ini files. Ini" For the Output As the # 1
Print # 1, "... "
Print # 1, "... "
Print # 1, "... "
Close # 1
End the If

CodePudding user response:

 Dim fs, f 
Set the fs=CreateObject (" Scripting. FileSystemObject ")
If Not the fs. FileExists (" C: \ test. Ini ") Then
The Set f=fs. CreateTextFile (" C: \ test. Ini ", True)
F.w riteline (" INI file content ")
F. lose
The Set f=Nothing
End the If
Set the fs=Nothing

CodePudding user response:

refer to the second floor dong_y888 response:
Visual Basic code
?



123456789

Dim the fs, Set the fs f=CreateObject (" Scripting. FileSystemObject ") If Not the fs. FileExists (" C: \ test. Ini ") Then Set f=fs. CreateTextFile (" C: \ test. In...


If you want to generate a WORD document

CodePudding user response:

CodePudding user response:

 Dim fs, f 
Set the fs=CreateObject (" Scripting. FileSystemObject ")
If Not the fs. FileExists (" C: \ test. Doc ") Then
The Set f=CreateObject (" Word. Application ")
F.d ocuments. Add
F.s election. Text="WORD document content"
F.a ctivedocument. Saveas "c: \ test. Doc"
F.q uit
The Set f=Nothing
End the If
Set the fs=Nothing

CodePudding user response:

If dir (Path)="" then
File does not exist
Create a file
end if

CodePudding user response:

If use API to read and write INI GetprivateprofileString series, is not to need to determine whether a file exists, read or write, and will automatically create the file does not exist

CodePudding user response:

INI file written and read have special API function can be implemented, because of the home won't be able to give you an example, but you can use baidu to search, should have relevant examples

CodePudding user response:

I was stupid way, for any file (not limited to the ini) are the same for

1, open the file
2, close the file
3, length of the file (after the first two steps, at this point the file must already exist)
If you take the file size is zero bytes, is likely (but not necessarily) is caused by the two steps before your new file, this time according to your needs, or write the file, or put the empty file deletion,

CodePudding user response:

Use FILESYSTEMOBJECT not more convenient (it's _ even?

CodePudding user response:

Batch bat file.
If not exist name. Ini echo config. Txt> Name. Ini


  • Related