Sunday, October 20, 2024

How to recursively copy all files from sub directories to a new directory in windows?

The directly solution was to use the below bash command

for /r Source %f in (*) do @copy /Y "%f" Destination

However it will prompt at all conflicts and we don't have an option to say No for all.

So I had to come up with this script instead

@echo off
setlocal enabledelayedexpansion

if "%~1"=="" (
    echo Source directory missing
    exit /b
)
if "%~2"=="" (
    echo Destination directory missing
    exit /b
)

set source=%~1
set destination=%~2

for /r "%source%" %%f in (*) do (
    set filename=%%~nf
    set extension=%%~xf
    set count=1
    set newname=%%~nf_!count!%%~xf
    if not exist "%destination%\!newname!" (
        copy "%%f" "%destination%\!newname!"
    ) else (
        :loop
        set /a count+=1
        set newname=%%~nf_!count!%%~xf
        if exist "%destination%\!newname!" goto loop
        copy "%%f" "%destination%\!newname!"
    )
)
endlocal

Sunday, June 14, 2015

What is running behind svchost?

Go to cmd and issue the command

tasklist /svc /fi "IMAGENAME eq svchost.exe