Yet another Xcopy question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

Yet another Xcopy question

#1 Post by kpropell » 06 May 2010 07:23

Is it possible to use this example from dostips:

Code: Select all

set sourcedir=c:\Documents and Settings\*.pst
set backupdir=c:\pstbackup
for /f "tokens=*" %%a in ('dir "%sourcedir%" /s/b') do (
    xcopy "%%a" "%backupdir%.%%~pa" /Y/U
)


With a .txt file containing lot's of .extensions?
Say I have this rawimage.txt file, and it contains some 40 extensions of different formats.
Call up the script and just search the whole partition.

Is that possible?

Cheer's
Kjell

jeb
Expert
Posts: 1042
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Yet another Xcopy question

#2 Post by jeb » 06 May 2010 07:47

Hi kpropell,

extend it to backup one extension at each call

Code: Select all

@echo off
setlocal EnableDelayedExpansion EnableExtensions
for /F "delims=" %%e in (rawimage.txt) do (
   echo backupExtension %%e
   call :backupExtension %%e
)
goto :eof

:backupExtension
set sourcedir=%CD%\pp\*.%~1
set backupdir=%cd%\backup\
for /f "tokens=*" %%a in ('dir "%sourcedir%" /s/b') do (
    xcopy "%%a" "%backupdir%.%%~pa" /Y
)
goto :eof


jeb

kpropell
Posts: 14
Joined: 24 Aug 2009 10:11

Re: Yet another Xcopy question

#3 Post by kpropell » 06 May 2010 09:56

Hi! Very good, it works :) Thank you so much.

I'm wondering why

Code: Select all

echo backupExtension %%e

is echo'd, when

Code: Select all

echo %%e

works just fine.

Kjell

edit:

I think it's starting to form.

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

Set SourcePath=%~0\..

:menuLOOP
cls
echo.
echo.= Menu =================================================
echo.
for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.  %%B  %%C
set choice=
echo.&set /p choice=Make a choice or hit ENTER to quit: ||GOTO:EOF
echo.&call:menu_%choice%
GOTO:menuLOOP

:menu_1   Backup-folder
cls
echo.Give the backup-folder a name
Set /p bfolder=[Input]:
md C:\%bfolder%
Set Wfolder=C:\%bfolder%
cls
echo.You're backup folder is located at: %Wfolder%
echo.
pause
GOTO:EOF

:menu_2   Driveletter
cls
echo LIST VOLUME > voltemp.txt && diskpart /s voltemp.txt && del /q voltemp.txt
echo.
echo. Ex; C: D: E: F:
Set /p WorkVolume=[Input]:
GOTO:EOF

:menu_3   Dir Backup-folder
cls
dir %Wfolder% /s/b
echo.
pause
GOTO:EOF

:menu_4   Explorer
cls
explorer %Wfolder%
GOTO:EOF

:menu_

:menu_5   List extensions
cls
type %SourcePath%\extensions.txt
echo.
pause
GOTO:EOF

:menu_6   Add extensions
cls
notepad %SourcePath%\extensions.txt
GOTO:EOF

:menu_7   Start backup
cls
for /F "delims=" %%e in (extensions.txt) do (
   echo %%e
   call :backupExtension %%e
)
GOTO:EOF

:backupExtension
set sourcedir=%WorkVolume%\*.%~1
set backupdir=%Wfolder%
for /f "tokens=*" %%a in ('dir "%sourcedir%" /s/b') do (
    xcopy "%%a" "%backupdir%.%%~pa" /Y
)
GOTO:EOF

Post Reply