<p>I am fairly new to Emacs and I have been trying to figure out how to change the default folder for <kbd>C-x C-f</kbd> on start-up. For instance when I first load Emacs and hit <kbd>C-x C-f</kbd> its default folder is <code>C:\emacs\emacs-21.3\bin</code>, but I would rather it be the desktop. I believe there is some way to customize the <code>.emacs</code> file to do this, but I am still unsure what that is.</p>

<p>Update: There are three solutions to the problem that I found to work, however I believe solution 3 is Windows only.</p>

<ul>
<li><p>Solution 1: Add <code>(cd "C:/Users/Name/Desktop")</code> to the <code>.emacs</code> file</p></li>
<li><p>Solution 2: Add <code>(setq default-directory "C:/Documents and Settings/USER_NAME/Desktop/")</code> to the <code>.emacs</code> file</p></li>
<li><p>Solution 3: Right click the Emacs short cut, hit properties and change the start in field to the desired directory.</p></li>
</ul>

[{'answer_id': 60481, 'author': 'vava', 'author_id': 6258, 'author_profile': 'https://Stackoverflow.com/users/6258', 'pm_score': 5, 'selected': False, 'text': '<p>I\'ve put </p>\n\n<pre><code>(cd "c:/cvsroot/")\n</code></pre>\n\n<p>in my .emacs and it did the job</p>\n'}, {'answer_id': 60482, 'author': 'Bart', 'author_id': 4343, 'author_profile': 'https://Stackoverflow.com/users/4343', 'pm_score': 8, 'selected': True, 'text': '<p>You didn\'t say so, but it sounds like you\'re starting Emacs from a Windows shortcut.</p>\n\n<p>The directory that you see with c-x c-f is the cwd, in Emacs terms, the <code>default-directory</code> (a variable).</p>\n\n<p>When you start Emacs using an MS Windows shortcut, the <code>default-directory</code> is initially the folder (directory) specified in the "Start In" field of the shortcut properties.  Right click  the shortcut, select <code>Properties</code>, and type the path to your desktop in the <code>Start In</code> field.</p>\n\n<p>If you\'re using Emacs from the command line, <code>default-directory</code> starts as the directory where you started Emacs (the cwd).</p>\n\n<p>This approach is better than editing your .emacs file, since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of Emacs if you need it.</p>\n\n<p><strong>CWD</strong> = <a href="http://linux.die.net/man/3/cwd" rel="noreferrer">current working directory</a> = <strong>PWD</strong> = <a href="http://en.wikipedia.org/wiki/Pwd" rel="noreferrer">present working directory</a>. It makes a lot more sense at the command line than in a GUI.</p>\n'}, {'answer_id': 60483, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 3, 'selected': False, 'text': "<p>As you're on Windows you can do it with a shortcut.</p>\n\n<p>Create a shortcut to <code>C:\\emacs\\emacs-21.3\\bin\\runemacs.exe</code>.  Edit the properties of the shortcut and change the value of <code>Start In:</code> to be whatever you want your default directory to be. </p>\n"}, {'answer_id': 60531, 'author': 'Eric Hansander', 'author_id': 5039, 'author_profile': 'https://Stackoverflow.com/users/5039', 'pm_score': 3, 'selected': False, 'text': '<p>The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in <code>C:\\dir_a</code>, then the working directory for that buffer will by default be <code>C:\\dir_a</code>. You can change this with <code>M-x cd</code> and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do <code>C-x C-f</code>).</p>\n\n<p>If you start emacs without opening a file, you will end up with the <code>*scratch*</code> buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with <code>M-x cd</code>, also from the <code>*scratch*</code> buffer.</p>\n\n<p>Finally, you can do as Vadim suggests and put</p>\n\n<pre><code>(cd "c:/dir_a/")\n</code></pre>\n\n<p>in your <code>.emacs</code> file, to make that directory the default no matter how you start emacs.</p>\n'}, {'answer_id': 65411, 'author': 'Michael', 'author_id': 9316, 'author_profile': 'https://Stackoverflow.com/users/9316', 'pm_score': 6, 'selected': False, 'text': '<p>I think the line you need to add to your .emacs is is </p>\n\n<pre><code>(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )\n</code></pre>\n\n<p>Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.</p>\n'}, {'answer_id': 602130, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting\n"Find file: C:\\Program Files\\emacs\\bin/" like Anton.\nI have HOME set to "C:\\Documents and settings\\USER NAME\\My Documents".\nThe response to C-x C-f I want in the minibuffer is "Find file: ~/". \nBy adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\\Documents and settings\\USER NAME\\My Documents/" which is functionally the same as "Find file: ~/". \nHowever, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.         </p>\n'}, {'answer_id': 2861104, 'author': 'Greg Laden', 'author_id': 344489, 'author_profile': 'https://Stackoverflow.com/users/344489', 'pm_score': 1, 'selected': False, 'text': '<p>I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory.  Since my emacs defaults to "home" I simply say:</p>\n\n<p>/Desktop/blank_file</p>\n\n<p>and that opens a file called "blank_file"</p>\n\n<p>That also moves the current working directory for that emacs session to the desktop.  </p>\n\n<p>If I happen to put stuff in "blank_file" then save it, of course, I\'ve got that stuff saved.  Which might be an annoyance or it might be a good thing, depending!</p>\n'}, {'answer_id': 2871389, 'author': 'Chris Huang-Leaver', 'author_id': 24508, 'author_profile': 'https://Stackoverflow.com/users/24508', 'pm_score': 5, 'selected': False, 'text': "<p>You can type the 'cd' emacs command.  ( M-x cd ) to change the default folder as a one off. </p>\n"}, {'answer_id': 2880860, 'author': 'Navidot', 'author_id': 346921, 'author_profile': 'https://Stackoverflow.com/users/346921', 'pm_score': 1, 'selected': False, 'text': '<p>To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:<br/>\n<br/>\n;;This works for Windows XP.<br/>\n(setq default-directory (concat "C:\\Documents and Settings\\MY_ACCOUNT\\DESKTOP\\"))</p>\n'}, {'answer_id': 17936147, 'author': 'Tonibat', 'author_id': 2632176, 'author_profile': 'https://Stackoverflow.com/users/2632176', 'pm_score': 0, 'selected': False, 'text': "<p>In Windows 8, it works to create a shortcut in the Desktop and change the property 'Start In:' for the shortcut. </p>\n\n<p>Now, I ran the program emacs-23.3\\bin\\addpm.exe as recommended, and the Windows-8 screen (that horrendous invention from Microsoft) it appeared an icon-link to Emacs. But there you have to change again the property 'Start In'. (It is different from the one in the desktop).\nJust right-click, choose in the bottom bar 'Open the file location' (or similar, I did it in my language), and you are taken to the folder with a new shortcut, in which you can (must) also change the property 'Start In:'.</p>\n\n<p>A little involved, but in fact very easy.</p>\n"}, {'answer_id': 38518073, 'author': 'Grant BlahaErath', 'author_id': 595504, 'author_profile': 'https://Stackoverflow.com/users/595504', 'pm_score': 0, 'selected': False, 'text': '<p>Since the most annoying thing is having windows Emacs dump you into system32 when you are just using the shortcut, but want every other case to work, just use a bit of elisp...</p>\n\n<p>(when (string&lt; "C:\\WINDOWS\\system32" default-directory) (setq default-directory "~/"))</p>\n\n<p>So it will only default to your home directory when you end up in system. The only drawback is if you really want to start emacs in system32...</p>\n'}, {'answer_id': 68941874, 'author': 'Gangula', 'author_id': 6908282, 'author_profile': 'https://Stackoverflow.com/users/6908282', 'pm_score': 1, 'selected': False, 'text': '<p>For windows users, the best way that I found is to create the shortcut for <code>runemacs.exe</code> and placing the shortcut in the root directory of my notes folder.</p>\n<p>This way, when you use this shortcut to open emacs, it will by default open in the root directory without having to specifically set the <code>Start In</code> property (<em>you can leave the <code>Start In</code> property blank</em>).</p>\n<blockquote>\n<p><a href="https://stackoverflow.com/a/17951772/6908282">Reference</a>: According to Microsoft, if you leave the \'Start In\' box empty, the script will run in the current working directory</p>\n</blockquote>\n<h2>TIP:</h2>\n<p>Additionally, if you have organized your notes into multiple root folders (Personal, Work etc...), you can copy multiple such shortcuts in each folder to open various instances of emacs with their own default directories.</p>\n'}]
['https://Stackoverflow.com/questions/60464', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/340/']