Skip to content

Commit

Permalink
show both copied and total files
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT committed Dec 8, 2022
1 parent 0b6e2dc commit 6372a20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3545,8 +3545,7 @@ private static bool DirectoryInfoHasChildItems(DirectoryInfo directory)
{
if (progressPreference == ActionPreference.Continue)
{
// we use a thread to gather the total files so that copying can start right away
Thread t = new Thread(() =>
Task t = new Task(() =>
{
GetTotalFiles(path, recurse);
});
Expand Down Expand Up @@ -3582,22 +3581,26 @@ private void GetTotalFiles(string path, bool recurse)
var dir = new DirectoryInfo(path);
var enumOptions = new EnumerationOptions();
enumOptions.IgnoreInaccessible = true;
if (recurse)
{
enumOptions.RecurseSubdirectories = true;
}
enumOptions.AttributesToSkip = 0;
enumOptions.RecurseSubdirectories = recurse;

foreach (var file in dir.EnumerateFiles("*", enumOptions))
{
_totalFiles++;
_totalBytes += file.Length;
if (!SessionStateUtilities.MatchesAnyWildcardPattern(file.Name, _excludeMatcher, defaultValue: false))
{
_totalFiles++;
_totalBytes += file.Length;
}
}
}
else
{
var file = new FileInfo(path);
_totalFiles++;
_totalBytes += file.Length;
if (!SessionStateUtilities.MatchesAnyWildcardPattern(file.Name, _excludeMatcher, defaultValue: false))
{
_totalFiles++;
_totalBytes += file.Length;
}
}
}
catch
Expand Down Expand Up @@ -3922,10 +3925,15 @@ private void CopyFileInfoItem(FileInfo file, string destinationPath, bool force,
double speed = (double)(_copiedBytes / 1024 / 1024) / _copyStopwatch.Elapsed.TotalSeconds;
var progress = new ProgressRecord(
COPY_FILE_ACTIVITY_ID,
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _totalFiles - _copiedFiles),
StringUtil.Format(FileSystemProviderStrings.CopyingLocalFileActivity, _copiedFiles, _totalFiles),
StringUtil.Format(FileSystemProviderStrings.CopyingLocalBytesStatus, Utils.DisplayHumanReadableFileSize(_copiedBytes), Utils.DisplayHumanReadableFileSize(_totalBytes), speed)
);
progress.PercentComplete = (int)((_copiedBytes * 100) / _totalBytes);
var percentComplete = (int)((_copiedBytes * 100) / _totalBytes);
if (percentComplete > 100)
{
percentComplete = 100;
}
progress.PercentComplete = percentComplete;
progress.RecordType = ProgressRecordType.Processing;
WriteProgress(progress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
<value>Destination path cannot be a subdirectory of the source: {0}.</value>
</data>
<data name="CopyingLocalFileActivity" xml:space="preserve">
<value>Copying {0} files</value>
<value>Copied {0} of {1} files</value>
</data>
<data name="CopyingLocalBytesStatus" xml:space="preserve">
<value>{0} of {1} ({2:0.0} MB/s)</value>
Expand Down

0 comments on commit 6372a20

Please sign in to comment.