This article's documentation is for anything that uses the Source engine. Click here for more information.

$pushd and $popd

From Valve Developer Community
Jump to: navigation, search

(in all games since Source 2006)

For GoldSrc GoldSrc and Source 2004 Source 2004, see $cd.

"$pushd" and "$popd" is a QC command available in all Source Source games. These commands 'push' and 'pop' directories to and from the QC's active folder, instead of writing out the foldernames in the smd file.
This can be useful in situations where you moved all models into a different folder while you're knee deep in a project and don't want to adjust all $model and $sequence lines to change the folder names.
Multiple $Pushd can be nested inside each other, so long as there are a corresponding number of $popd.

Note.pngNote:$Pushd does not require to have a $Popd counterpart. If you don't need to define any more models in the rest of the qc file, you can just leave a $Pushd laying around without ever popping back.
Warning.pngWarning:Heavy usage of $Pushd and $Popd may be confusing and requires lots of space. See the last part of "Advanced Nesting" as an example.


$pushd <path>


In The following examples, we got a "Project" folder containing the QC file and a "Models" folder. The "Models" folder has a "Anims" subfolder.

Not Nested

$pushd "models"					//Enter "models" folder
	$model Cam1 "camera_body.smd"
	$model Cam2 "camera_arms.smd"
$popd							//Undoing previous $Pushd. Essentially leaving "models" folder

$pushd "models/anims"			//Enter "models/anims" folder
	$sequence	idle "idle.smd"
$popd							//Undoing previous $Pushd.


$pushd "models"						//Enter "models" folder
	$model Cam1 "camera_body.smd"
	$model Cam2 "camera_arms.smd"
	$pushd "anims"					//Previous $Pushd made us enter "models" folder. Now from here, we enter "anims"
		$sequence	idle "idle.smd"
	$popd							//Undoing previous $Pushd. But now we're back in "models". So we need one more $Popd.
$popd							    //You can either write two $Popd on one line, or use $Pushd "../../" to jump out two folders in one command

Advanced Nesting

In this example, we have a "Project" folder which contains the folders "QCs", "Models" and "Anims".
The QC is in the "QCs" folder, which we first need to leave using $Pushd "../", followed by the folder we want to jump into.

$pushd "../models"					//Leave QCs folder and immediately enter "models" folder.
	$model Cam1 "camera_body.smd"
	$model Cam2 "camera_arms.smd"

	$pushd "../anims"				// Instead of using $Popd followed by $Pushd, we jump straight into the anims folder from here.
		$sequence	idle "idle.smd"
$popd								//Undoing previous $Pushd. Since we undid the $pushd "../models" by using $pushd "../anims", we got a single directory we pushed into. Therefore needing a single $popd

But at some point its way easier to just define folders in the smd string instead of keeping track of your $Pushd and $Popd.
Defining the model files like this, without $Pushd and $Popd requires less space and achieves the same effect.

$model 		Cam1 "../models/camera_body.smd"
$model 		Cam2 "../models/camera_arms.smd"
$sequence	idle "../anims/idle.smd"