# WinFileSystem

Import: `import com.install4j.api.windows.WinFileSystem;`

```java
public class WinFileSystem
```

Collection of static methods to access Microsoft Windows-specific
folder locations and to execute native file system operations.

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`getSpecialFolder(SpecialFolder, boolean)`](#getspecialfolder-specialfolder-boolean) | `File` | Returns Windows-specific directories like the start menu or the desktop. |
| [`getProgramFilesDirectory()`](#getprogramfilesdirectory) | `File` | Returns the program files directory of the current Windows installation. |
| [`getCommonFilesDirectory()`](#getcommonfilesdirectory) | `File` | Returns a folder for components that are shared across applications. |
| [`getProgramDataDirectory()`](#getprogramdatadirectory) | `File` | Returns the program data directory where applications can save data that is not specific to particular users. |
| [`getWindowsDirectory()`](#getwindowsdirectory) | `File` | Returns the Windows directory. |
| [`getSystemDirectory()`](#getsystemdirectory) | `File` | Returns the system directory. |
| [`createShellLink(File, File, File)`](#createshelllink-file-file-file) | `boolean` | Creates a shell link. |
| [`createShellLink(File, File, File, String)`](#createshelllink-file-file-file-string) | `boolean` | Creates a shell link. |
| [`createShellLink(File, File, File, String, String)`](#createshelllink-file-file-file-string-string) | `boolean` | Creates a shell link. |
| [`createShellLink(File, File, File, String, String, File)`](#createshelllink-file-file-file-string-string-file) | `boolean` | Creates a shell link. |
| [`createShellLink(File, File, File, String, String, File, ShowCommand)`](#createshelllink-file-file-file-string-string-file-showcommand) | `boolean` | Creates a shell link. |
| [`createStartMenuEntry(String, String, File, boolean, File)`](#createstartmenuentry-string-string-file-boolean-file) | `void` | Creates a start menu entry. |
| [`createStartMenuEntry(String, String, File, boolean, File, String)`](#createstartmenuentry-string-string-file-boolean-file-string) | `void` | Creates a start menu entry. |
| [`createStartMenuEntry(String, String, File, boolean, File, String, boolean)`](#createstartmenuentry-string-string-file-boolean-file-string-boolean) | `void` | Creates a start menu entry. |
| [`moveWithDelayUntilReboot(File, File)`](#movewithdelayuntilreboot-file-file) | `boolean` | Calls the win32 API function MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT. |
| [`getDriveType(File)`](#getdrivetype-file) | `DriveType` | Tests on what kind of drive the given file is (or would be) located. |

### getSpecialFolder(SpecialFolder, boolean)

```java
public static File getSpecialFolder(SpecialFolder folderType, boolean allUsers)
```

Returns Windows-specific directories like the start menu or the
desktop.


**Parameters:**

- `folderType` — specifies the requested folder type.
- `allUsers` — if this parameter is `true` and if the current user is in the
Administrators group, the method returns the requested folder for all users.
Otherwise, it returns the folder for the current user.

**Returns:** the requested folder location.

### getProgramFilesDirectory()

```java
public static File getProgramFilesDirectory()
```

Returns the program files directory of the current Windows installation.
A typical path is `C:\Program Files`.


**Returns:** the program files directory.

### getCommonFilesDirectory()

```java
public static File getCommonFilesDirectory()
```

Returns a folder for components that are shared across applications.
A typical path is `C:\Program Files\Common Files`.


**Returns:** the common files directory.

### getProgramDataDirectory()

```java
public static File getProgramDataDirectory()
```

Returns the program data directory where applications can save data that is not specific to particular users.
A typical path is `C:\ProgramData`.


**Returns:** the common files directory.

### getWindowsDirectory()

```java
public static File getWindowsDirectory()
```

Returns the Windows directory.
A typical path is `C:\Windows`.


**Returns:** the Windows directory.

### getSystemDirectory()

```java
public static File getSystemDirectory()
```

Returns the system directory.
A typical path is `C:\Windows\system32`


**Returns:** the system directory.

### createShellLink(File, File, File)

```java
public static boolean createShellLink(File file, File shortcutTo, File iconFile)
```

Creates a shell link.
Note that Windows might change the link suffix from `lnk` to `pif`,
if you are linking to a DOS executable or a batch file.
This is the same as calling `createShellLink(file, shortcutTo, iconFile, null, null)`


**Parameters:**

- `file` — the shell link that should be created including the `lnk` suffix.
- `shortcutTo` — the file it should link to.
- `iconFile` — an optional icon file. If `null` is passed, the default icon of the
`shortcutTo` target will be used.

**Returns:** whether the link could be created or not.

**See also:**

- [WinFileSystem.createShellLink](WinFileSystem.md#createshelllink-file-file-file-string)

### createShellLink(File, File, File, String)

```java
public static boolean createShellLink(File file, File shortcutTo, File iconFile, String arguments)
```

Creates a shell link.
Note that Windows might change the link suffix from `lnk` to `pif`,
if you are linking to a DOS executable or a batch file.
This is the same as calling `createShellLink(file, shortcutTo, iconFile, arguments, null)`


**Parameters:**

- `file` — the shell link that should be created including the `lnk` suffix.
- `shortcutTo` — the file it should link to.
- `iconFile` — an optional icon file. If `null` is passed, the default icon of the
`shortcutTo` target will be used.
- `arguments` — the arguments passed to the target.

**Returns:** whether the link could be created or not.

### createShellLink(File, File, File, String, String)

```java
public static boolean createShellLink(File file, File shortcutTo, File iconFile, String arguments, String description)
```

Creates a shell link.
Note that Windows might change the link suffix from `lnk` to `pif`,
if you are linking to a DOS executable or a batch file.


**Parameters:**

- `file` — the shell link that should be created including the `lnk` suffix.
- `shortcutTo` — the file it should link to.
- `iconFile` — an optional icon file. If `null` is passed, the default icon of the
`shortcutTo` target will be used.
- `arguments` — the arguments passed to the target.
- `description` — the description used in the tooltip

**Returns:** whether the link could be created or not.

### createShellLink(File, File, File, String, String, File)

```java
public static boolean createShellLink(File file, File shortcutTo, File iconFile, String arguments, String description, File startIn)
```

Creates a shell link.
Note that Windows might change the link suffix from `lnk` to `pif`,
if you are linking to a DOS executable or a batch file.


**Parameters:**

- `file` — the shell link that should be created including the `lnk` suffix.
- `shortcutTo` — the file it should link to.
- `iconFile` — an optional icon file. If `null` is passed, the default icon of the
`shortcutTo` target will be used.
- `arguments` — the arguments passed to the target.
- `description` — the description used in the tooltip
- `startIn` — the working directory for the executable

**Returns:** whether the link could be created or not.

### createShellLink(File, File, File, String, String, File, ShowCommand)

```java
public static boolean createShellLink(File file, File shortcutTo, File iconFile, String arguments, String description, File startIn, ShowCommand showCommand)
```

Creates a shell link.
Note that Windows might change the link suffix from `lnk` to `pif`,
if you are linking to a DOS executable or a batch file.


**Parameters:**

- `file` — the shell link that should be created including the `lnk` suffix.
- `shortcutTo` — the file it should link to.
- `iconFile` — an optional icon file. If `null` is passed, the default icon of the
`shortcutTo` target will be used.
- `arguments` — the arguments passed to the target.
- `description` — the description used in the tooltip
- `startIn` — the working directory for the executable
- `showCommand` — the window show command

**Returns:** whether the link could be created or not.

### createStartMenuEntry(String, String, File, boolean, File)

```java
public static void createStartMenuEntry(String folder, String entryName, File destination, boolean allUsers, File icon) throws IOException
```

Creates a start menu entry.


**Parameters:**

- `folder` — the name of the folder where the entry should be created. Leave empty for top-level entries.
- `entryName` — the name of the menu entry. You can create subfolders with backslashes.
- `destination` — the file that should be linked to
- `allUsers` — whether the entry should be created for all users or not
- `icon` — an optional icon file. If `null` is passed, the default icon of the
`destination` target will be used.

**Throws:**

- `IOException` — if the start menu entry could not be created

### createStartMenuEntry(String, String, File, boolean, File, String)

```java
public static void createStartMenuEntry(String folder, String entryName, File destination, boolean allUsers, File icon, String arguments) throws IOException
```

Creates a start menu entry.


**Parameters:**

- `folder` — the name of the folder where the entry should be created. Leave empty for top-level entries.
- `entryName` — the name of the menu entry. You can create subfolders with backslashes.
- `destination` — the file that should be linked to
- `allUsers` — whether the entry should be created for all users or not
- `icon` — an optional icon file. If `null` is passed, the default icon of the
`destination` target will be used.
- `arguments` — optional arguments given to the destination. Can be `null`

**Throws:**

- `IOException` — if the start menu entry could not be created

### createStartMenuEntry(String, String, File, boolean, File, String, boolean)

```java
public static void createStartMenuEntry(String folder, String entryName, File destination, boolean allUsers, File icon, String arguments, boolean runAsAdministrator) throws IOException
```

Creates a start menu entry.


**Parameters:**

- `folder` — the name of the folder where the entry should be created. Leave empty for top-level entries.
- `entryName` — the name of the menu entry. You can create subfolders with backslashes.
- `destination` — the file that should be linked to
- `allUsers` — whether the entry should be created for all users or not
- `icon` — an optional icon file. If `null` is passed, the default icon of the
`destination` target will be used.
- `arguments` — optional arguments given to the destination. Can be `null`
- `runAsAdministrator` — whether the entry should be run as administrator

**Throws:**

- `IOException` — if the start menu entry could not be created

### moveWithDelayUntilReboot(File, File)

```java
public static boolean moveWithDelayUntilReboot(File source, File destination)
```

Calls the win32 API function MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT.
You must be an administrator to call this function.


**Parameters:**

- `source` — the source file. Must be on the same drive as the destination file.
- `destination` — the destination file. If empty, the source file will be deleted.

**Returns:** true if the operation could be registered successfully.

### getDriveType(File)

```java
public static DriveType getDriveType(File file)
```

Tests on what kind of drive the given file is (or would be) located.


**Parameters:**

- `file` — an existing or non-existing file

**Returns:** a constant of [`DriveType`](DriveType.md).

