Difference between revisions of "IFileSystem"

From Valve Developer Community
Jump to: navigation, search
(My Game Directory)
(cleanup, pov, 2nd level headlines, code tags, folder->directory)
Line 1: Line 1:
[[Category:Programming]]
+
Here you will find all the information you ever wanted to know about the File System in [[Source]].  How to open files, how to read files, how to create new directories and how to find a file on the local system.
=Introduction=
+
 
Here you will find all the information you ever wanted to know about the File System in Source.  How to open files, how to read files, how to create new directories and how to find a file on the local system.
+
==My Game Directory==
 +
 
 +
This does not deal specifically with the filesystem, but you might find this useful for your project.
 +
 
 +
//Server
 +
char * pGameDir = new char[1024];
 +
engine->GetGameDir(pGameDir, 1024);
 +
 +
//Client
 +
const char *pGameDir = engine->GetGameDirectory();
 +
 
 +
==Create Directory==
  
=My Game Directory=
+
To create a directory you need to know two things; the '''relative path''' containing the new directory name and '''Path ID''' where the path will be created — called a Path ID because it does not appear to be possible to create a directory using anything other than a search path id.
This does not deal specifically with the filesystem, but I could not find this information anywhere else on the wiki, and so you may find this useful for your project.
 
<pre>
 
//Server
 
char * pGameDir = new char[1024];
 
engine->GetGameDir(pGameDir, 1024);
 
</pre>
 
<pre>
 
//Client
 
const char *pGameDir = engine->GetGameDirectory();
 
</pre>
 
  
=Create Directory=
+
===Default Path Ids===
To create a directory you need to know two things.  The the <b>relative path</b> containing the new directory name and <b>Path ID</b> where the path will be created.  I say Path ID because it does not appear to be possible to create a directory using anything other than a search path id.
 
  
Default Path Ids:<br/>
+
* <code>DEFAULT_WRITE_PATH</code>
"DEFAULT_WRITE_PATH"<br/>
+
* <code>MOD</code>
"MOD"<br/>
+
* <code>GAME</code>
"GAME"<br/>
+
* <code>GAMEBIN</code>
"GAMEBIN"<br/>
 
  
 
Example:
 
Example:
<pre>
 
char * relpath = new char[1024];
 
Q_snprintf(relpath, 1024, "stuff\\%s", "newdirectory");
 
filesystem->CreateDirHierarchy( path, "MOD" );
 
</pre>
 
  
This code will create a "newdirectory" in your "stuff" folder, which if does not exist will be created along with "newdirectory" inside of your MOD folder.
+
char * relpath = new char[1024];
 +
Q_snprintf(relpath, 1024, "stuff\\%s", "newdirectory");
 +
filesystem->CreateDirHierarchy( path, "MOD" );
 +
 
 +
This code will create a <code>newdirectory</code> in your <code>stuff</code> directory, which if does not exist will be created along with <code>newdirectory</code> inside of your MOD directory.
 +
 
 +
==Open File==
  
=Open File=
+
==Close File==
  
=Close File=
+
==Search Files==
  
=Search Files=
+
[[Category:Programming]]

Revision as of 10:37, 17 April 2006

Here you will find all the information you ever wanted to know about the File System in Source. How to open files, how to read files, how to create new directories and how to find a file on the local system.

My Game Directory

This does not deal specifically with the filesystem, but you might find this useful for your project.

//Server
char * pGameDir = new char[1024];
engine->GetGameDir(pGameDir, 1024);

//Client
const char *pGameDir = engine->GetGameDirectory();

Create Directory

To create a directory you need to know two things; the relative path containing the new directory name and Path ID where the path will be created — called a Path ID because it does not appear to be possible to create a directory using anything other than a search path id.

Default Path Ids

  • DEFAULT_WRITE_PATH
  • MOD
  • GAME
  • GAMEBIN

Example:

char * relpath = new char[1024];
Q_snprintf(relpath, 1024, "stuff\\%s", "newdirectory");
filesystem->CreateDirHierarchy( path, "MOD" );

This code will create a newdirectory in your stuff directory, which if does not exist will be created along with newdirectory inside of your MOD directory.

Open File

Close File

Search Files