Move Directory then delete directory on destination

First I need to search a UNC path \\FW18\shared\Essbase\Backups or %targetdir% for any directory ending in the variable 'dayofweek' and delete that directory. So if %dayofweek%=fri than any folder ending in fri is deleted.  No prompts, etc.. force deleted. Non case sensitive.

Second I need to 'move' a whole folder named %shortname% to a UNC path \\FW18\shared\Essbase\Backups which is a variable too named 'targetdir'.  It needs to move it no matter what.  No prompting and overwrite if target directory already exists.  %shortname% example is '03262010_Fri'

I prefer windows batch as I'm currently trying to modify and existing .bat file to do this.  Having issues with UNC path.. Batch doesn't like it?  I can xcopy it ok, just cant figure out how to move etc....
elwayisgodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thompsonwirelessCommented:
I would be interested in seeing your batch file.  You can't use a UNC path as a directory name unless it is a mapped drive as far as I know.  I do know I can't CD to \\whatever\

Just about everything else you want to do appears to be basic move, del., copy, etc.
0
sr75Commented:
Here is an example script of how to do it in vbscript.  How it populates the variables is up to you.

arrFrom = array("C:\03252010_Thu",_
		"C:\03262010_Fri")

ToFold = "\\FW18\shared\Essbase\Backups"

Set FSO = CreateObject("Scripting.FileSystemObject")

For Cnt = 0 to ubound(arrFrom)
		FSO.CopyFolder arrFrom(Cnt), ToFold
		FSO.DeleteFolder arrFrom(Cnt)
Next

Open in new window

0
elwayisgodAuthor Commented:
@echo off

setlocal ENABLEDELAYEDEXPANSION

:: Define constants
set BASEDIR=%Base_Dir%
set BACKUPPATH=%Backup_Path%%

echo/

:: Verify directories exist
if not exist "%BASEDIR%" (
      echo ERROR - Base directory does NOT exist
      echo        = '%BASEDIR%
      goto :END
)
if not exist "%BACKUPPATH%" (
      md "%BACKUPPATH%" 2>nul
      if errorlevel 1 (
            echo ERROR - unable to create backup directory
            echo        = '%BACKUPPATH%'
            goto :END
      )
)

:: Construct target directory name
set tmpSTRING=%DATE:~4%
for /f "tokens=5" %%d in ('echo/^|date^|find "current date"') do set DAYOFWEEK=%%d
set SHORTNAME=%tmpSTRING:/=%_%DAYOFWEEK%
set TARGETDIRECTORY=%BACKUPPATH%\%SHORTNAME%

:: Verify target directory does not already exist
if exist "%TARGETDIRECTORY%" (
      echo ERROR - target directory already exists
      echo        = '%TARGETDIRECTORY%'
      echo/
      echo     + deleting '%TARGETDIRECTORY%'
      rd /s /q "%TARGETDIRECTORY%" >nul
      if not errorlevel 1 (
            echo       - Done
            echo/
      ) else (
            echo       # ERROR - failed to delete target directory
            goto :END
      )
)

echo + Moving 'Daily' directory structure
echo   - SOURCE: '%BASEDIR%'
echo   - TARGET: '%TARGETDIRECTORY%'

:: Move files
 move "%BASEDIR%" "%TARGETDIRECTORY%" 1>nul 2>&1
 if errorlevel 1 (
      echo ERROR - an error occurred while moving the files
      goto :END
 )



:: Recreate new 'Daily' directories
md "%BASEDIR%" 2>nul
md "%BASEDIR%\Essbase_Bkup"
md "%BASE_DIR%\App_Logs"
REM md "%BASEDIR%\Planning_Bkup"
REM md "%BASEDIR%\BusRules_Bkup"
REM md "%BASEDIR%\SharedSvcs_Bkup"
REM md "%BASEDIR%\WebAnalysis_Bkup"



if errorlevel 1 (
      echo ERROR - an error occurred while creating the new 'Daily' directory
      echo        = '%BASEDIR%'
      goto :END
)

:: Search for previous same-day directory and remove if found
for /f %%d in ('dir /ad /b "%BACKUPPATH%\*%DAYOFWEEK%" ^| find /v /i "%SHORTNAME%"') do (
      echo/
      echo   + removing same-day backups from previous weeks:
      echo    = '%%d'
      cd %BACKUPPATH%
      rd /s /q "%%d"
            if errorlevel 1 (
            echo ERROR - unable to remove previous backup directory
            goto :END
      )
)


:: Copy the Essbase_Backup_Log.log file from the TARGETDIRECTORY location to 'Backup\MaxL' :: directory.  This is needed as the email script is in VB and cannot recognize the TARGETDIRECTORY :: variable. Thus will copy it to where all the scripts reside and in VB script hard code in
:: the location where it needs to attach the log file.  Easier than trying to have the VB script :: find the TARGETDIRECTORY.
:: Then the next VB script will attach it to the email that is sent out.

xcopy %TARGETDIRECTORY%\Essbase_Backup_Log.log %ess_scripts_bkup%\*.* /Y

REM Now move the 'Daily' backup to the remote server

REM xcopy E:\Backup\Weekly\*%DAYOFWEEK% Y:\ /Y /S /E /i

echo / Complete

goto :END

:: Define functions
:END
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

elwayisgodAuthor Commented:
sr75,

not sure how to read this....You hardcoded in paths there.. I can't have that.. Not a vbscript person....
0
elwayisgodAuthor Commented:
I can do a remove directory with RMDIR.  However how do I say remove a directory where it ends with 'fri' which is a variable named 'dayofweek'.  thats what I can't figure out...

rmdir %targetdir%*%dayofweek% /s /q

That does not work.. Can't figure out how to do it...
0
sr75Commented:
I hardcoded the paths to show you where they go.
0
AmazingTechCommented:
for /f "tokens=*" %%a in ('dir /ad /s "%TargetDir%\*%dayofweek%" ^| findstr /e /i /c:"%dayofweek%"') do (
    echo Removing "%%a"
    rmdir /s /q "%%a"
)
0
elwayisgodAuthor Commented:
Hi,

I tried it but it's not working.  Not sure how to decipher as it looks to me like it's trying to remove a directory I created '03192010_Fri'.  However is it trying in the \\FW18\shared\Essbase\Backups directory?  It says it cant find it but not sure where it's looking........


E:\Backup\maxl>for /F "tokens=*" %a in ('dir /ad /s "\\FW18\shared\Essbase\Backu
ps\*Fri" | findstr /e /i /c:"Fri"') do (
echo Removing "%a"
 rmdir /s /q "%a"
)

E:\Backup\maxl>(
echo Removing "03/26/2010  03:29 PM    <DIR>          03192010_Fri"
 rmdir /s /q "03/26/2010  03:29 PM    <DIR>          03192010_Fri"
)
Removing "03/26/2010  03:29 PM    <DIR>          03192010_Fri"
The system cannot find the path specified.
E:\Backup\maxl>
0
AmazingTechCommented:
Opps. Missed the /b

for /f "tokens=*" %%a in ('dir /b /ad /s "%TargetDir%\*%dayofweek%" ^| findstr /e /i /c:"%dayofweek%"') do (
    echo Removing "%%a"
    rmdir /s /q "%%a"
)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.