Skip to content

Commit ec78468

Browse files
Merge pull request #6578 from MicrosoftDocs/main
Auto Publish – main to live - 2026-03-31 23:04 UTC
2 parents 754b403 + c543573 commit ec78468

57 files changed

Lines changed: 1236 additions & 1536 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.openpublishing.redirection.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11379,6 +11379,61 @@
1137911379
"source_path": "hub/apps/desktop/visual-studio-templates.md",
1138011380
"redirect_url": "/windows/apps/dev-tools/visual-studio",
1138111381
"redirect_document_id": false
11382+
},
11383+
{
11384+
"source_path": "uwp/files/quickstart-listing-files-and-folders.md",
11385+
"redirect_url": "/windows/apps/develop/files/list-files-folders",
11386+
"redirect_document_id": false
11387+
},
11388+
{
11389+
"source_path": "uwp/files/quickstart-reading-and-writing-files.md",
11390+
"redirect_url": "/windows/apps/develop/files/create-read-write-files",
11391+
"redirect_document_id": false
11392+
},
11393+
{
11394+
"source_path": "uwp/files/best-practices-for-writing-to-files.md",
11395+
"redirect_url": "/windows/apps/develop/files/best-practices-writing-files",
11396+
"redirect_document_id": false
11397+
},
11398+
{
11399+
"source_path": "uwp/files/quickstart-getting-file-properties.md",
11400+
"redirect_url": "/windows/apps/develop/files/file-properties",
11401+
"redirect_document_id": false
11402+
},
11403+
{
11404+
"source_path": "uwp/files/quickstart-determining-availability-of-microsoft-onedrive-files.md",
11405+
"redirect_url": "/windows/apps/develop/files/determine-availability-microsoft-onedrive-files",
11406+
"redirect_document_id": false
11407+
},
11408+
{
11409+
"source_path": "uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries.md",
11410+
"redirect_url": "/windows/apps/develop/files/music-pictures-videos-libraries",
11411+
"redirect_document_id": false
11412+
},
11413+
{
11414+
"source_path": "uwp/files/thumbnails.md",
11415+
"redirect_url": "/windows/apps/develop/files/thumbnails",
11416+
"redirect_document_id": false
11417+
},
11418+
{
11419+
"source_path": "uwp/files/how-to-track-recently-used-files-and-folders.md",
11420+
"redirect_url": "/windows/apps/develop/files/track-recently-used-files-folders",
11421+
"redirect_document_id": false
11422+
},
11423+
{
11424+
"source_path": "uwp/files/change-tracking-filesystem.md",
11425+
"redirect_url": "/windows/apps/develop/files/change-tracking-filesystem",
11426+
"redirect_document_id": false
11427+
},
11428+
{
11429+
"source_path": "uwp/files/file-access-permissions.md",
11430+
"redirect_url": "/windows/apps/develop/files/file-access-permissions",
11431+
"redirect_document_id": false
11432+
},
11433+
{
11434+
"source_path": "uwp/files/fast-file-properties.md",
11435+
"redirect_url": "/windows/apps/develop/files/fast-file-properties",
11436+
"redirect_document_id": false
1138211437
}
1138311438
]
1138411439
}

uwp/files/best-practices-for-writing-to-files.md renamed to hub/apps/develop/files/best-practices-writing-files.md

Lines changed: 32 additions & 32 deletions
Large diffs are not rendered by default.

uwp/files/change-tracking-filesystem.md renamed to hub/apps/develop/files/change-tracking-filesystem.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ title: Track file system changes in the background
33
description: Describes how to track changes in files and folders in the background as users move them around the system.
44
ms.date: 12/19/2018
55
ms.topic: how-to
6-
keywords: windows 10, uwp
6+
keywords: windows 10, winui
77
ms.localizationpriority: medium
88
---
99

1010
# Track file system changes in the background
1111

1212
**Important APIs**
1313

14-
- [**StorageLibraryChangeTracker**](/uwp/api/Windows.Storage.StorageLibraryChangeTracker)
15-
- [**StorageLibraryChangeReader**](/uwp/api/windows.storage.storagelibrarychangereader)
16-
- [**StorageLibraryChangedTrigger**](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger)
17-
- [**StorageLibrary**](/uwp/api/windows.storage.storagelibrary)
14+
- [StorageLibraryChangeTracker](/uwp/api/Windows.Storage.StorageLibraryChangeTracker)
15+
- [StorageLibraryChangeReader](/uwp/api/windows.storage.storagelibrarychangereader)
16+
- [StorageLibraryChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger)
17+
- [StorageLibrary](/uwp/api/windows.storage.storagelibrary)
1818

19-
The [**StorageLibraryChangeTracker**](/uwp/api/Windows.Storage.StorageLibraryChangeTracker) class allows apps to track changes in files and folders as users move them around the system. Using the **StorageLibraryChangeTracker** class, an app can track:
19+
The [StorageLibraryChangeTracker](/uwp/api/Windows.Storage.StorageLibraryChangeTracker) class allows apps to track changes in files and folders as users move them around the system. Using the StorageLibraryChangeTracker class, an app can track:
2020

2121
- File operations including add, delete, modify.
2222
- Folder operations such as renames and deletes.
2323
- Files and folders moving on the drive.
2424

25-
Use this guide to learn the programing model for working with the change tracker, view some sample code, and understand the different types of file operations that are tracked by **StorageLibraryChangeTracker**.
25+
Use this guide to learn the programing model for working with the change tracker, view some sample code, and understand the different types of file operations that are tracked by StorageLibraryChangeTracker.
2626

27-
**StorageLibraryChangeTracker** works for user libraries, or for any folder on the local machine. This includes secondary drives or removable drives but does not include NAS drives or network drives.
27+
StorageLibraryChangeTracker works for user libraries, or for any folder on the local machine. This includes secondary drives or removable drives but does not include NAS drives or network drives.
2828

2929
## Using the change tracker
3030

@@ -41,7 +41,7 @@ The next sections walk through each of the steps with some code examples. The co
4141

4242
### Enable the change tracker
4343

44-
The first thing that the app needs to do is to tell the system that it is interested in change tracking a given library. It does this by calling the [**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) method on the change tracker for the library of interest.
44+
The first thing that the app needs to do is to tell the system that it is interested in change tracking a given library. It does this by calling the [Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) method on the change tracker for the library of interest.
4545

4646
```csharp
4747
StorageLibrary videosLib = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
@@ -51,14 +51,14 @@ videoTracker.Enable();
5151

5252
A few important notes:
5353

54-
- Make sure your app has permission to the correct library in the manifest before creating the [**StorageLibrary**](/uwp/api/windows.storage.storagelibrary) object. See [File Access Permissions](./file-access-permissions.md) for more details.
55-
- [**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) is thread safe, will not reset your pointer, and can be called as many times as you like (more on this later).
54+
- Make sure your app has permission to the correct library in the manifest before creating the [StorageLibrary](/uwp/api/windows.storage.storagelibrary) object. See [File Access Permissions](./file-access-permissions.md) for more details.
55+
- [Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) is thread safe, will not reset your pointer, and can be called as many times as you like (more on this later).
5656

5757
![Enabling an empty change tracker](images/changetracker-enable.png)
5858

5959
### Wait for changes
6060

61-
After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register to be activated any time there is a change by registering for the [**StorageLibraryChangedTrigger**](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) event.
61+
After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register to be activated any time there is a change by registering for the [StorageLibraryChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) event.
6262

6363
![Changes being added to the change tracker without the app reading them](images/changetracker-waiting.png)
6464

@@ -78,11 +78,11 @@ The app is then responsible for processing the changes into its own experience o
7878
![Reading the changes from the change tracker into an app database](images/changetracker-reading.png)
7979

8080
> [!TIP]
81-
> The second call to enable is to defend against a race condition if the user adds another folder to the library while your app is reading changes. Without the extra call to **Enable** the code will fail with ecSearchFolderScopeViolation (0x80070490) if the user is changing the folders in their library
81+
> The second call to enable is to defend against a race condition if the user adds another folder to the library while your app is reading changes. Without the extra call to Enable the code will fail with ecSearchFolderScopeViolation (0x80070490) if the user is changing the folders in their library
8282
8383
### Accept the changes
8484

85-
After the app is done processing the changes, it should tell the system to never show those changes again by calling the [**AcceptChangesAsync**](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync) method.
85+
After the app is done processing the changes, it should tell the system to never show those changes again by calling the [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync) method.
8686

8787
```csharp
8888
await changeReader.AcceptChangesAsync();
@@ -92,8 +92,8 @@ await changeReader.AcceptChangesAsync();
9292

9393
The app will now only receive new changes when reading the change tracker in the future.
9494

95-
- If changes have happened between calling [**ReadBatchAsync**](/uwp/api/windows.storage.storagelibrarychangereader.readbatchasync) and [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync), the pointer will be only be advanced to the most recent change the app has seen. Those other changes will still be available the next time it calls **ReadBatchAsync**.
96-
- Not accepting the changes will cause the system to return the same set of changes the next time the app calls **ReadBatchAsync**.
95+
- If changes have happened between calling [ReadBatchAsync](/uwp/api/windows.storage.storagelibrarychangereader.readbatchasync) and [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync), the pointer will be only be advanced to the most recent change the app has seen. Those other changes will still be available the next time it calls ReadBatchAsync.
96+
- Not accepting the changes will cause the system to return the same set of changes the next time the app calls ReadBatchAsync.
9797

9898
## Important things to remember
9999

@@ -103,24 +103,24 @@ When using the change tracker, there are a few things that you should keep in mi
103103

104104
Although we try to reserve enough space in the change tracker to hold all the operations happening on the system until your app can read them, it is very easy to imagine a scenario where the app doesn’t read the changes before the circular buffer overwrites itself. Especially if the user is restoring data from a backup or syncing a large collection of pictures from their camera phone.
105105

106-
In this case, **ReadBatchAsync** will return the error code [**StorageLibraryChangeType.ChangeTrackingLost**](/uwp/api/windows.storage.storagelibrarychangetype). If your app receives this error code, it means a couple things:
106+
In this case, ReadBatchAsync will return the error code [StorageLibraryChangeType.ChangeTrackingLost](/uwp/api/windows.storage.storagelibrarychangetype). If your app receives this error code, it means a couple things:
107107

108108
* The buffer has overwritten itself since the last time you looked at it. The best course of action is to recrawl the library, because any information from the tracker will be incomplete.
109-
* The change tracker will not return any more changes until you call [**Reset**](/uwp/api/windows.storage.storagelibrarychangetracker.reset). After the app calls reset, the pointer will be moved to the most recent change and tracking will resume normally.
109+
* The change tracker will not return any more changes until you call [Reset](/uwp/api/windows.storage.storagelibrarychangetracker.reset). After the app calls reset, the pointer will be moved to the most recent change and tracking will resume normally.
110110

111111
It should be rare to get these cases, but in scenarios where the user is moving a large number of files around on their disk we don’t want the change tracker to balloon and take up too much storage. This should allow apps to react to massive file system operations while not damaging the customer experience in Windows.
112112

113113
### Changes to a StorageLibrary
114114

115-
The [**StorageLibrary**](/uwp/api/windows.storage.storagelibrary) class exists as a virtual group of root folders that contain other folders. To reconcile this with a file system change tracker, we made the following choices:
115+
The [StorageLibrary](/uwp/api/windows.storage.storagelibrary) class exists as a virtual group of root folders that contain other folders. To reconcile this with a file system change tracker, we made the following choices:
116116

117-
- Any changes to descendent of the root library folders will be represented in the change tracker. The root library folders can be found using the [**Folders**](/uwp/api/windows.storage.storagelibrary.folders) property.
118-
- Adding or removing root folders from a **StorageLibrary** (through [**RequestAddFolderAsync**](/uwp/api/windows.storage.storagelibrary.requestaddfolderasync) and [**RequestRemoveFolderAsync**](/uwp/api/windows.storage.storagelibrary.requestremovefolderasync)) will not create an entry in the change tracker. These changes can be tracked through the [**DefinitionChanged**](/uwp/api/windows.storage.storagelibrary.definitionchanged) event or by enumerating the root folders in the library using the [**Folders**](/uwp/api/windows.storage.storagelibrary.folders) property.
117+
- Any changes to descendent of the root library folders will be represented in the change tracker. The root library folders can be found using the [Folders](/uwp/api/windows.storage.storagelibrary.folders) property.
118+
- Adding or removing root folders from a StorageLibrary (through [RequestAddFolderAsync](/uwp/api/windows.storage.storagelibrary.requestaddfolderasync) and [RequestRemoveFolderAsync](/uwp/api/windows.storage.storagelibrary.requestremovefolderasync)) will not create an entry in the change tracker. These changes can be tracked through the [DefinitionChanged](/uwp/api/windows.storage.storagelibrary.definitionchanged) event or by enumerating the root folders in the library using the [Folders](/uwp/api/windows.storage.storagelibrary.folders) property.
119119
- If a folder with content already in it is added to the library, there will not be a change notification or change tracker entries generated. Any subsequent changes to the descendants of that folder will generate notifications and change tracker entries.
120120

121121
### Calling the Enable method
122122

123-
Apps should call [**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) as soon as they start tracking the file system and before every enumeration of the changes. This will ensure that all changes will be captured by the change tracker.
123+
Apps should call [Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) as soon as they start tracking the file system and before every enumeration of the changes. This will ensure that all changes will be captured by the change tracker.
124124

125125
## Putting it together
126126

0 commit comments

Comments
 (0)