Created
August 4, 2025 22:31
-
-
Save smasongarrison/c393d0f2200800409980ae8f48923d52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------ | |
# Script: mark-rproj-user-ignored.ps1 | |
# Description: Recursively searches for .Rproj.user or .git folders in R | |
# projects under a given directory and marks them to | |
# be ignored by Dropbox using NTFS alternate data streams. | |
# | |
# Author: Mason Garrison | |
# Created: 2025-08-04 | |
# ------------------------------------------------------------ | |
# Set the root directory to scan and the log output file | |
$root = "E:\Dropbox\Lab" | |
$logPath = "E:\Dropbox\Lab\dropbox_user_folders_log.txt" | |
$ignoredfolder = ".git" | |
#$ignoredfolder = ".Rproj.user" | |
# Timestamp for this run | |
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
Add-Content -Path $logPath -Value "`n=== Run at $timestamp ===" | |
# Recursively find all directories named ".Rproj.user" | |
$projUserDirs = Get-ChildItem -Path $root -Directory -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $ignoredfolder } | |
# If nothing found, log it | |
if ($projUserDirs.Count -eq 0) { | |
Add-Content -Path $logPath -Value "No $ignoredfolder folders found." | |
Write-Output "No $ignoredfolder folders found." | |
} else { | |
foreach ($dir in $projUserDirs) { | |
try { | |
Set-Content -Path $dir.FullName -Stream "com.dropbox.ignored" -Value 1 -Force | |
Add-Content -Path $logPath -Value "Marked: $($dir.FullName)" | |
Write-Output "Marked: $($dir.FullName)" | |
} | |
catch { | |
Add-Content -Path $logPath -Value "FAILED: $($dir.FullName) - $($_.Exception.Message)" | |
Write-Warning "FAILED: $($dir.FullName) - $($_.Exception.Message)" | |
} | |
} | |
} | |
# Timestamp for this run | |
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
Add-Content -Path $logPath -Value "`n=== Done at $timestamp ===" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment