tags:

views:

54

answers:

2

I haven't had a chance to test this script, I'm just using it as a suitable pseudocode. It's just supposed to copy all files in the current directory into a timestamped subdirectory.

ID="$(date +%Y%b%d%H%M%S)"
COMMITABLE="$(ls | egrep --invert-match ^(STATES|PARENT)\$)"
STATE_PATH="$(pwd)/STATES/$ID"
mkdir --parents "$STATE_PATH"
cp $COMMITABLE "$STATE_PATH"
ln -s "$STATE_PATH" PARENT
+1  A: 

Here you go. This is from my own scripts:

set now=%date:~-4%-%date:~-10,2%-%date:~-7,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%

rem Before 10:00 o'clock a space is used, this makes it a zero.
set now=%now: =0%

xcopy . copydir-%now% /i

One word of warning: this uses the US date format. For matching a different format you will have to change it. As I work with Dutch and US systems I personally use this code:

rem US date versus Dutch: test 5th char is /
if "%date:~-5,1%"=="/" (
   rem Date format is mm/dd/yyyy
   set now=%date:~-4%-%date:~-10,2%-%date:~-7,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
) else (
   rem Date format is dd-mm-yyyy
   set now=%date:~-4%-%date:~-7,2%-%date:~-10,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
)
Matijs
Thanks, but wouldn't that end up copying all of the previous copydirs into the new one, 'causing the directory size to blow up?
Jeremy Banks
No it will not as I did not specify /s so no sub-directories are copied. I usually do make a copy with sub-directories but then not to a sub-directory of the current directory. Use xcopy /? to find out about the /EXCLUDE option if that is what you want.
Matijs
A: 

A friend who doesn't post here gave me this, which excludes the directories:

@echo off
set thedate=%date:~0,2%-%date:~3,2%-%date:~6,4%
md %thedate%
echo STATES > excludefile.txt
echo PARENT > excludefile.txt
echo excludefile.txt >> excludefile.txt
xcopy <root folder of directory structure> %thedate% /e /i /exclude:excludefile.txt
del excludefile.txt
Jeremy Banks