---
title: "How do you move a file to another directory?"  
description: "How do you move a file to another directory?"  
author: "ICSM Computer"  
published: 2025-05-05  
updated: 2025-05-19  
canonical: https://www.mindstick.com/forum/161574/how-do-you-move-a-file-to-another-directory  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How do you move a file to another directory?

How do you move a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) to another [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp)?

## Replies

### Reply by Anubhav Sharma

In C#, you can **move a file to another directory** using the `File.Move` method from the `System.IO` namespace.

### Syntax:

```cs
File.Move(string sourceFileName, string destFileName);
```

1. `sourceFileName`: Full path of the file you want to move.
2. `destFileName`: Full path where you want the file moved.

### Example:

```cs
using System.IO;
File.Move(@"C:\source\file.txt", @"C:\destination\file.txt");
```

This moves `file.txt` from `C:\source` to `C:\destination`.

### Important Notes:

1. If the **destination file already exists**, an `IOException` is thrown. There’s no built-in `overwrite` option for `File.Move`, so you'd have to delete the destination file first if needed.
2. If the **destination directory doesn't exist**, a `DirectoryNotFoundException` is thrown.
3. The move can occur **across different directories** or even **different drives**, and the method handles that internally.

### Optional: Overwrite manually if needed

```cs
string source = @"C:\source\file.txt";
string destination = @"C:\destination\file.txt";

if (File.Exists(destination))
{
    File.Delete(destination); // Delete the existing file if overwrite is intended
}

File.Move(source, destination);
```


---

Original Source: https://www.mindstick.com/forum/161574/how-do-you-move-a-file-to-another-directory

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
