- 1 year ago
How to skip .svn directories and included files in Windows cmd script?
To skip .svn directories and their included files in a Windows CMD script, you can use a combination of for
loops and conditional statements to iterate through the directory tree and exclude the .svn directories. Here's an example of how you can achieve this:
batch@echo off
setlocal enabledelayedexpansion
set "source_dir=C:\path\to\your\source\directory"
set "destination_dir=C:\path\to\your\destination\directory"
for /R "%source_dir%" %%F in (*) do (
set "skipFile="
for /F "delims=" %%D in ('dir /B /AD "%%~dpF.svn" 2^>nul') do set "skipFile=1"
if not defined skipFile (
echo Copying "%%F" to "%destination_dir%\%%~pnxF"
copy "%%F" "%destination_dir%\%%~pnxF" >nul
)
)
echo Done!
Replace C:\path\to\your\source\directory
with the path to the root directory of your source files, and C:\path\to\your\destination\directory
with the path to the destination directory where you want to copy the files (excluding the .svn directories).
This script uses two nested for
loops. The outer loop (for /R
) iterates through all files recursively in the source directory and its subdirectories. For each file, it checks if there is a corresponding .svn directory in the same location (using the inner loop with dir /AD
). If the .svn directory exists, the file is skipped (by setting skipFile
to a non-empty value). Otherwise, the file is copied to the destination directory, preserving the relative directory structure (%%~pnxF
extracts the relative path and filename without the drive letter).
The >nul
at the end of the copy
command suppresses the output, so only the "Copying" messages and the "Done!" message will be displayed in the console.
Please note that this script assumes that you want to copy the files to a different destination directory while excluding the .svn directories. Adjust the source_dir
and destination_dir
variables accordingly for your specific use case. Additionally, always test the script on a backup of your files to ensure that it behaves as expected before using it on important data.