none
ROBO COBY RRS feed

  • Question

  • Hello friends,

    i need to copy some folders one location to other by using robo copy.

    conditions are;

    1. copy the folder names which are start with alphabet "T" with extension of two letters.

    2. do not copy the folder names which are start with alphabet "T" with more the two extension.

    I have created one batch for this process but that program copies all folders which are start with "T"

    echo off

    set TOOLHOME=%~dp0
    set TOOLNAME=%~n0

    :=== for Backup =======================
    set SOURCE=D:\LocalData
    set TARGET=D:\test3
    :======================================

    :-------------------------
    echo I will copy from "%SOURCE%" to "%TARGET%".
    set /p yesno=Can I start? [Y/N]

    if "%yesno%" == "y" goto :START
    if "%yesno%" == "Y" goto :START
    echo Canceled.

    START
    FOR /D /R %SOURCE% IN (T*) DO ROBOCOPY "%SOURCE%" "%TARGET%\DTS%~pG%~nxG" /E /S /NP
    echo Done.

    pause>nul

    Please provide solution for this ....

    thanks in advance

    regards

    krishnamoorthy

    Friday, August 1, 2014 9:35 AM

Answers

  •  @echo off
     SET WhereTolook=C:\Admin\testfolder
     SET TargetFolder=C:\Admin\targetfolder
     FOR /F "delims=*" %%G IN ('dir "%WhereTolook%" /B /AD ^| FINDSTR T..$') DO copy "%WhereTolook%\%%G" "%TargetFolder%" /y


    • Edited by LomM Friday, August 1, 2014 11:32 AM Error on the script. Now it works even if the script is NOT in the same folder
    • Marked as answer by ScriptingWifeModerator Tuesday, September 16, 2014 6:28 PM
    Friday, August 1, 2014 10:41 AM
  • Get-ChildItem "source path" | where {$_.Name.length -lt 4} | Copy-Item -Destination "Destination path" -Recurse

    The above will work in Powershell apart from when I tested it interestingly I had to run it twice as for some reason it missed the first folder every time. Might be a glitch on my machine or a very strange bug.

    Friday, August 1, 2014 1:00 PM
  • You should be able to change (T*) to (T??).

    Asterisk (*) matches 0 or more characters.

    Question mark(?) matches exactly one character.

    Friday, August 1, 2014 1:18 PM

All replies

  • for /f %%I in ('dir /ad  /b T??') do  @echo %%I


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Friday, August 1, 2014 1:48 PM
    Friday, August 1, 2014 9:59 AM
  •  @echo off
     SET WhereTolook=C:\Admin\testfolder
     SET TargetFolder=C:\Admin\targetfolder
     FOR /F "delims=*" %%G IN ('dir "%WhereTolook%" /B /AD ^| FINDSTR T..$') DO copy "%WhereTolook%\%%G" "%TargetFolder%" /y


    • Edited by LomM Friday, August 1, 2014 11:32 AM Error on the script. Now it works even if the script is NOT in the same folder
    • Marked as answer by ScriptingWifeModerator Tuesday, September 16, 2014 6:28 PM
    Friday, August 1, 2014 10:41 AM
  • Get-ChildItem "source path" | where {$_.Name.length -lt 4} | Copy-Item -Destination "Destination path" -Recurse

    The above will work in Powershell apart from when I tested it interestingly I had to run it twice as for some reason it missed the first folder every time. Might be a glitch on my machine or a very strange bug.

    Friday, August 1, 2014 1:00 PM
  • You should be able to change (T*) to (T??).

    Asterisk (*) matches 0 or more characters.

    Question mark(?) matches exactly one character.

    Friday, August 1, 2014 1:18 PM
  • In PowerShell - same as DOS

    GEt-ChildItem  * -include T??

    Use wildcard match characters.


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Friday, August 1, 2014 1:50 PM
    Friday, August 1, 2014 1:50 PM