We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Avoiding Archive Attribute In Batch Files

Medium Priority
498 Views
Last Modified: 2012-05-07
I use this batch file for quick data backing up in XP SR3

DEL C:\BACKUP\DATAONLY\*.* /Q /F /S
RMDIR C:\BACKUP\DATAONLY\DATA\ /Q /S

XCOPY W:\DATA\*.* C:\BACKUP\DATAONLY\DATA /I /S /E /K /R /H
==================================================
It works fine except that all the copied file have the archive attribue set to on.
I know it not really that important but I'd prefer an exact copy including attributes
Can it be done in XP DOS Batch files?
==================================================
ATTRIB -A C:\BACKUP\DATAONLY\DATA\*.* /s

This clears the archive attributes except for hidden files.
It's no good anyway as I'd still like an exact copy.
Comment
Watch Question

Technology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
I'm positive with RoboCopy. It is preserving the file attributes by default (/COPY:DAT = Data, Attributes, Timestamps).
EirmanChief Operations Manager
CERTIFIED EXPERT

Author

Commented:
Many thanks - The ss64 website was a revelation to me and definitely warrents points.

I'll leave the question open for a week or so to see if anyone can come up with a windows/dos solution
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
You will not succeed. All available integrated commands besides backup und restore do not retain Archive bit.
Lee W, MVPTechnology and Business Process Advisor
CERTIFIED EXPERT
Most Valuable Expert 2013

Commented:
Robocopy is a utility by Microsoft in the resource kit.  It is included as part of the OS in 2008 and I believe Vista.  Is there a reason you don't want to use it?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Minor correction on the above script.  Add "\DATA" to "C:\BACKUP\DATAONLY\%%~b" so that it becomes "C:\BACKUP\DATAONLY\DATA\%%~b".  Similar goes for the three prior FOR commands as well.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
M_Intuit,

If using no delims, "tokens=1*" does not make sense. As there are no delimiters, the first token is the complete line. "tokens=1 delims=" is the same as "tokens=1* delims=" and "delims=".

I can not see any bug in the FOR interpretation. However, you should STRICTLY avoid overlapping for variables.
for /F "tokens=1* delims=" %%a ... would allow for %%a and %%b to be set. Using %%b in the next FOR might confuse the interpreter, and give all kind of strange bugs. It's a good idea to separate both FOR variable sets by case, or start the second with a non-overlapping name.
E.g.
for /f "delims=" %%A in ('dir W:\Data /a:a /b /s') do @for /f "tokens=2* delims=\" %%c in ("%%~A") do attrib +a "C:\BACKUP\DATAONLY\DATA\%%~d"

Eirman,
The tokens=3* resp. tokens=2* are hardcoded and depending on the target folder start depth (C:\BACKUP\DATAONLY == 3 directory name parts).

I would not take that path, as it is error-prone, and performs bad:
* Files already copied in a previous run are copied again
* The target and source folders are traversed 6 times each, plus the delete and copy.

RoboCopy was implemented by Microsoft for those purposes. It's fast, reliable and robust, even with open files. And it is included (in a expanded version) with Vista and 2008.

Commented:
Greetings Glemo.  If you simply excise the buggy FOR statement and place it on a single line as I already did, you can confirm the bug.

Regarding "delims=1* delims=" there is no problem there.  THe purpose of the asterisk is to tell the command interpreter to place all following text under the specified variable.

So if specified variable is "%a" then "%b" means nothing when then asterisk is used.  Without the asterisk, "%b" then suddenly has meaning.

The above addresses and applies to your misperception on overlapping variables.  Reference "FOR /?" for more details.

Again, if you simply excise the buggy FOR statement and place it on a single line as I already did, you can confirm the bug.

Also understand that files aren't being "COPIED AGAIN" when the end of the FOR statements contain an "ATTRIB" command as opposed to "XCOPY" or "COPY" etc.

My post wasn't intended to counter your potentially helpful suggestion to use ROBOCOPY, only address the author's preference for a solution that doesn't involve changing the default configuration for every machine that the script is run on by installing a Resource Kit or adding the ROBOCOPY program file.
EirmanChief Operations Manager
CERTIFIED EXPERT

Author

Commented:
Thanks for all your contributions. I'll live with minor "archive" flaw for the moment and try out robocopy when I get the time.
I'll also experiment with the interesting script above .

I only have XP disks - I presume I can download robocopy and all the other utilities from the MS website
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
EirmanChief Operations Manager
CERTIFIED EXPERT

Author

Commented:
Thanks again

Commented:
Definitely some issues; and this is one of several limitations I've run into over the years.  This would likely be better done via VBS.  

In the past there seemed to be a difference between how "tokens=3*" and "tokens=3,*" were interpreted.  Now they appear to mean precisely the same.   "tokens=3" of course has always meant the same; that only one variable is assigned meaning.

With the comma (tokens=3,*) it would simply be an automatted continuance of letter variable assigments... essentially the same as specifying 'delims=3,4,5,6,7, .... 52'.  Not the case now.

Without the comma (tokens=3*) {I THOUGHT} it meant that %a would contain everything including the delimiter in one variable.  Per "FOR /?" it is indeed %b that gets everything, not %a.    Now that I've gone back over it I vaguelyremember running into this limitation some years ago.

===================
21:06:19.60
Wed 07/01/2009
Windows Environment
E:\Tmp\Command>for /?
............
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

    would parse each line in myfile.txt, ignoring lines that begin with
    a semicolon, passing the 2nd and 3rd token from each line to the for
    body, with tokens delimited by commas and/or spaces.  Notice the for
    body statements reference %i to get the 2nd token, %j to get the
    3rd token, and %k to get all remaining tokens after the 3rd.  For
    file names that contain spaces, you need to quote the filenames with
    double quotes.  In order to use double quotes in this manner, you also
    need to use the usebackq option, otherwise the double quotes will be
    interpreted as defining a literal string to parse.

    %i is explicitly declared in the for statement and the %j and %k
    are implicitly declared via the tokens= option.  You can specify up
    to 26 tokens via the tokens= line, provided it does not cause an
    attempt to declare a variable higher than the letter 'z' or 'Z'.
    Remember, FOR variables are single-letter, case sensitive, global,
    and you can't have more than 52 total active at any one time.
..............................
========================

BEHAVIOR ON FOR SYNTAX:
 
16:03:52.13
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=3 delims=\" %a in ('dir "E:\Tmp" /b /aas /s') do @
echo attrib +a +s "C:\BACKUP\DATAONLY\%~a" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Cookies" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\History" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
 
 
16:04:12.90
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=3* delims=\" %a in ('dir "E:\Tmp" /b /aas /s') do
@echo attrib +a +s "C:\BACKUP\DATAONLY\%~a" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Cookies"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\History"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909" FSum_MD5_27065.Chk %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" test-attrib.txt %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" TEST_ATTRIB\TEST_FILE_ATTRIB.Txt %~c
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons" Thumbs.db %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" cmldr %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" ntldr %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" NTDETECT.COM %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" BootSect.DOS %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" Boot.Ini %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" IO.SYS %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" MSDOS.SYS %~c
 
 
16:04:19.27
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=3,* delims=\" %a in ('dir "E:\Tmp" /b /aas /s') do
 @echo attrib +a +s "C:\BACKUP\DATAONLY\%~a" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Cookies"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\History"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db"  %~c
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909" FSum_MD5_27065.Chk %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" test-attrib.txt %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" TEST_ATTRIB\TEST_FILE_ATTRIB.Txt %~c
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons" Thumbs.db %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" cmldr %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" ntldr %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" NTDETECT.COM %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" BootSect.DOS %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" Boot.Ini %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" IO.SYS %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" MSDOS.SYS %~c

Open in new window

Commented:
But anyway, here's the proof on a work-around...

Just means you'll have to double-up on the commands and expect that a bunch of errors be returned on the second command.

Simply clean it up and make the necessary reflective changes to the script.  That would be a 100% native solution you asked for.


16:15:42.42
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=3 delims=\" %a in ('dir "E:\Tmp" /b /aas /s') do @
echo attrib +a +s "C:\BACKUP\DATAONLY\%~a" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Cookies" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\History" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip" %~b %~c
 
 
 
 
16:14:32.72
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=3* delims=\" %a in ('dir "E:\Tmp" /b /aas /s') do
@echo attrib +a +s "C:\BACKUP\DATAONLY\%~a\%~b" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Cookies\" %~c
attrib +a +s "C:\BACKUP\DATAONLY\History\" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1\" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files\" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db\" %~c
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909\FSum_MD5_27065.Chk" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command\test-attrib.txt" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Command\TEST_ATTRIB\TEST_FILE_ATTRIB.Txt" %~c
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons\Thumbs.db" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\cmldr" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\ntldr" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\NTDETECT.COM" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\BootSect.DOS" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\Boot.Ini" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\IO.SYS" %~c
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Z
ip\MSDOS.SYS" %~c

Open in new window

Commented:
Final working script (just added three lines) with proof of work following post...

                                     MD "C:\BACKUP\DATAONLY"
@if not EXIST "C:\Backup" (@echo ABORTING: Cannot find "C:\Backup" directory.&@pause&@goto :EOF)
cd /d "C:\Backup"
 
DEL /q /f /s "C:\BACKUP\DATAONLY\*"
RD /s /q "C:\BACKUP\DATAONLY\DATA"
 
%SystemRoot%\System32\XCopy.Exe "W:\DATA\*" "C:\BACKUP\DATAONLY\DATA" /I /S /E /K /R /H
REM ATTRIB -A C:\BACKUP\DATAONLY\DATA\* /s
 
REM 1) remove the archive attribute from all files on C: (preserving H and S attributes)
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY /aa /b /s') do attrib -a "%%~a"
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY /aah /b /s') do attrib -a +h "%%~a"
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY /aas /b /s') do attrib -a +s "%%~a"
 
REM 2) Read which files have the archive attribute applied on W:
REM 3) Apply the archive attribute to select files on C:
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aa /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a "C:\BACKUP\DATAONLY\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aa /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a "C:\BACKUP\DATAONLY\%%~b\%%~c"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aah /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +h "C:\BACKUP\DATAONLY\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aah /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +h "C:\BACKUP\DATAONLY\%%~b\%%~c"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aas /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +s "C:\BACKUP\DATAONLY\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aas /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +s "C:\BACKUP\DATAONLY\%%~b\%%~c""
 
REM !! The only thing that prevents this from working is a Microsoft BUG.  FOR command is ignoring the asterisk so "tokens=3*" is treated exactly the same as "tokens=3".
REM A work-around is possible but that will require more time.  (which I don't have at the moment)
 
 
=========================
PROOF OF WORK
=========================
17:59:54.31
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=1* delims=" %a in ('dir E:\Tmp /as /b /s') do @for
 /f "tokens=3* delims=\" %b in ("%~a") do @echo attrib +a "C:\BACKUP\DATAONLY\%~
b"
attrib +a "C:\BACKUP\DATAONLY\Cookies"
attrib +a "C:\BACKUP\DATAONLY\History"
attrib +a "C:\BACKUP\DATAONLY\Tempor~1"
attrib +a "C:\BACKUP\DATAONLY\Temporary Internet Files"
attrib +a "C:\BACKUP\DATAONLY\Thumbs.db"
attrib +a "C:\BACKUP\DATAONLY\07y02m09d_001909"
attrib +a "C:\BACKUP\DATAONLY\Command"
attrib +a "C:\BACKUP\DATAONLY\Command"
attrib +a "C:\BACKUP\DATAONLY\DefaultEmoticons"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
 
 
18:00:10.46
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=1* delims=" %a in ('dir E:\Tmp /as /b /s') do @for
 /f "tokens=3* delims=\" %b in ("%~a") do @echo attrib +a "C:\BACKUP\DATAONLY\%~
b\%~c"
attrib +a "C:\BACKUP\DATAONLY\Cookies\"
attrib +a "C:\BACKUP\DATAONLY\History\"
attrib +a "C:\BACKUP\DATAONLY\Tempor~1\"
attrib +a "C:\BACKUP\DATAONLY\Temporary Internet Files\"
attrib +a "C:\BACKUP\DATAONLY\Thumbs.db\"
attrib +a "C:\BACKUP\DATAONLY\07y02m09d_001909\FSum_MD5_27065.Chk"
attrib +a "C:\BACKUP\DATAONLY\Command\test-attrib.txt"
attrib +a "C:\BACKUP\DATAONLY\Command\TEST_ATTRIB\TEST_FILE_ATTRIB.Txt"
attrib +a "C:\BACKUP\DATAONLY\DefaultEmoticons\Thumbs.db"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
cmldr"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
ntldr"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
NTDETECT.COM"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
BootSect.DOS"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
Boot.Ini"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
IO.SYS"
attrib +a "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
MSDOS.SYS"
 
 
18:01:23.95
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>

Open in new window

Commented:
Removed last remark; add +s on proof; add \Data to for statements.
                                     MD "C:\BACKUP\DATAONLY"
@if not EXIST "C:\Backup" (@echo ABORTING: Cannot find "C:\Backup" directory.&@pause&@goto :EOF)
cd /d "C:\Backup"
 
DEL /q /f /s "C:\BACKUP\DATAONLY\*"
RD /s /q "C:\BACKUP\DATAONLY\DATA"
 
%SystemRoot%\System32\XCopy.Exe "W:\DATA\*" "C:\BACKUP\DATAONLY\DATA" /I /S /E /K /R /H
REM ATTRIB -A C:\BACKUP\DATAONLY\DATA\* /s
 
REM 1) remove the archive attribute from all files on C: (preserving H and S attributes)
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY\DATA /aa /b /s') do attrib -a "%%~a"
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY\DATA /aah /b /s') do attrib -a +h "%%~a"
for /f "tokens=1* delims=" %%a in ('dir C:\BACKUP\DATAONLY\DATA /aas /b /s') do attrib -a +s "%%~a"
 
REM 2) Read which files have the archive attribute applied on W:
REM 3) Apply the archive attribute to select files on C:
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aa /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a "C:\BACKUP\DATAONLY\DATA\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aa /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a "C:\BACKUP\DATAONLY\DATA\%%~b\%%~c"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aah /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +h "C:\BACKUP\DATAONLY\DATA\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aah /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +h "C:\BACKUP\DATAONLY\DATA\%%~b\%%~c"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aas /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +s "C:\BACKUP\DATAONLY\DATA\%%~b"
for /f "tokens=1* delims=" %%a in ('dir W:\Data /aas /b /s') do @for /f "tokens=3* delims=\" %%b in ("%%~a") do attrib +a +s "C:\BACKUP\DATAONLY\DATA\%%~b\%%~c""
 
 
 
 
 
 
=========================
PROOF OF WORK
=========================
17:59:54.31
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=1* delims=" %a in ('dir E:\Tmp /as /b /s') do @for
 /f "tokens=3* delims=\" %b in ("%~a") do @echo attrib +a +s "C:\BACKUP\DATAONLY\%~
b"
attrib +a +s "C:\BACKUP\DATAONLY\Cookies"
attrib +a +s "C:\BACKUP\DATAONLY\History"
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files"
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db"
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909"
attrib +a +s "C:\BACKUP\DATAONLY\Command"
attrib +a +s "C:\BACKUP\DATAONLY\Command"
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip"
 
 
 
18:00:10.46
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>for /f "tokens=1* delims=" %a in ('dir E:\Tmp /as /b /s') do @for
 /f "tokens=3* delims=\" %b in ("%~a") do @echo attrib +a +s "C:\BACKUP\DATAONLY\%~
b\%~c"
attrib +a +s "C:\BACKUP\DATAONLY\Cookies\"
attrib +a +s "C:\BACKUP\DATAONLY\History\"
attrib +a +s "C:\BACKUP\DATAONLY\Tempor~1\"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Internet Files\"
attrib +a +s "C:\BACKUP\DATAONLY\Thumbs.db\"
attrib +a +s "C:\BACKUP\DATAONLY\07y02m09d_001909\FSum_MD5_27065.Chk"
attrib +a +s "C:\BACKUP\DATAONLY\Command\test-attrib.txt"
attrib +a +s "C:\BACKUP\DATAONLY\Command\TEST_ATTRIB\TEST_FILE_ATTRIB.Txt"
attrib +a +s "C:\BACKUP\DATAONLY\DefaultEmoticons\Thumbs.db"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
cmldr"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
ntldr"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
NTDETECT.COM"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
BootSect.DOS"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
Boot.Ini"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
IO.SYS"
attrib +a +s "C:\BACKUP\DATAONLY\Temporary Directory 1 for RootFiles_08y01m17d.Zip\
MSDOS.SYS"
 
 
18:01:23.95
Mon 07/06/2009
Windows Environment
E:\Tmp\Command>

Open in new window

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.