<p>When I defragment my XP machine I notice that there is a block of "Unmovable Files". Is there a file attribute I can use to make my own files unmovable?</p>

<p>Just to clarify, I want a way to programmatically tell Windows that a file that I create should be unmovable. Is this possible, and if so, how can I do it?</p>

<p>Thanks,</p>

<p>Terry </p>

[{'answer_id': 52183, 'author': 'Abdu', 'author_id': 5232, 'author_profile': 'https://Stackoverflow.com/users/5232', 'pm_score': 0, 'selected': False, 'text': "<p>I assume you're using the defragger that comes with Windows. Some commercial ones like DiskKeeper can move some of these files (usually system files). You can try their trial versions.</p>\n"}, {'answer_id': 52189, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 1, 'selected': False, 'text': "<p>This usually means that the file is in use by some process. If you're defragmenting, you'll likely see this with a lot of system files. If the file should legitimately be movable and is stuck (it's being held by a process that runs at startup but shouldn't be, for example), the most useful way of resolving the problem is to remove all permissions on the file, reboot, restore the permissions, and then get rid of the file/run the program that's trying to use it.</p>\n"}, {'answer_id': 52196, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 4, 'selected': True, 'text': '<p>A lot of system files cannot be moved after the system boots, such as the page file and registry database files.</p>\n\n<p><a href="http://technet.microsoft.com/en-us/sysinternals/bb897426.aspx" rel="noreferrer">This utility</a> runs before Windows boots to defragment those files.  I have it set to run at every boot, and it works well for me on several machines.</p>\n\n<p>Note that the very first time you boot up with this utility set to run, it may take several minutes to defrag.  After that first run though, it finishes in just 3 or 4 seconds.</p>\n\n<p><em>Edit0: To respond to your clarification- that link says windows has marked the page file and registry files as open for exclusive access.  So you should be able to do the same thing with the <a href="http://msdn.microsoft.com/en-us/library/aa365202(VS.85).aspx" rel="noreferrer">LockFile</a> API Call.  However, that\'s not an attribute of the file itself.  You\'d have to actually run some background program that locks the file for exclusive access.</em></p>\n'}, {'answer_id': 52219, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Contig might serve your purpose <a href="http://technet.microsoft.com/en-us/sysinternals/bb897428.aspx" rel="nofollow noreferrer">http://technet.microsoft.com/en-us/sysinternals/bb897428.aspx</a></p>\n\n<p>I\'m relatively certain I ran across some methods/attributes you could access programatically to do exactly what you want.  This was back in NT4 days though and my memory isn\'t that good.</p>\n'}, {'answer_id': 52220, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 1, 'selected': False, 'text': "<p>I suppose the ugly way is to have an application boot on startup, check every few seconds if defrag is running and if so open the file in exclusive mode.</p>\n\n<p>This is really ugly and I don't recommend it unless there is no cleaner solution.</p>\n"}, {'answer_id': 52222, 'author': 'Chris Driver', 'author_id': 5217, 'author_profile': 'https://Stackoverflow.com/users/5217', 'pm_score': 1, 'selected': False, 'text': '<p>Terry, the answers all mention ways to prevent files from becoming unmovable during defragmentation. From your question it appears that you are in fact wanting to <em>make</em> your personal files unmovable. Can you please clarify what is appealing about making your files unmovable.</p>\n'}, {'answer_id': 52268, 'author': 'ddowns', 'author_id': 5201, 'author_profile': 'https://Stackoverflow.com/users/5201', 'pm_score': 0, 'selected': False, 'text': '<p>For a little more complete solution try Raxco\'s PerfectDisk. While it is a commercial product it does a very good job and supports boot time defrag of system files. The first defrag takes longer than say DiskKeeper but its a single pass defragger and supports defragging with very little free space left on the drive. Overall its a much smarter defrag program then any other I\'ve seen and supports systems of any size.</p>\n\n<p><a href="http://www.raxco.com/" rel="nofollow noreferrer">http://www.raxco.com/</a></p>\n'}, {'answer_id': 52509, 'author': 'Mark', 'author_id': 4405, 'author_profile': 'https://Stackoverflow.com/users/4405', 'pm_score': 2, 'selected': False, 'text': "<p>There are no file attributes that you can place on your files to mark them as immovable.  The only way that a file cannot be moved (I think) during defragmentation is to have some other process have the file open (for read or write, I'm not even sure that you need to have the file open in exclusive mode or not).</p>\n\n<p>Quite frankly, I cannot think of a reason that you'd want your files not to move, unless you have specific requirements about where on the disk platter your files reside.  Defragmentation should generally lead to faster disk access and that seems to be desireable in all cases :-)</p>\n"}, {'answer_id': 8934006, 'author': 'Galvion', 'author_id': 1044601, 'author_profile': 'https://Stackoverflow.com/users/1044601', 'pm_score': 0, 'selected': False, 'text': '<p>first try to move(or delete) the files within safe mode. If can not, try to move(or delete) the files with linux.</p>\n\n<p>But be careful if those are the windows system files, then you are failed to boot up your windows.</p>\n\n<p>Some reason why the files are unmovable are : the file size is too big, the files are being in open/in use condition, insufficient security privileges, being access by other computer/s, and many other things.</p>\n'}]
['https://Stackoverflow.com/questions/52172', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2171/']