copy /w deletes hidden files and excluded files

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#2
| Suppose there are no hidden files in Dir2. If I do
|
| copy /w Dir1\* Dir2\
|
| then the hidden files in Dir2 will be deleted. Similarly, if there
| is no file Bar.txt in Dir1 and I do
|
| copy /w /[!Bar.txt] Dir1\ Dir2\
|
| then any file Dir2\Bar.txt will be deleted. Is this WAD? It seems a
| bit odd.

Deleting of all hidden files from the target that are absent in the source,
hidden ones included, is what I'd expect /w to achieve. As to the second
case, it has incorrect syntax (the file exclusion option is supposed to
precede the /w option), but regardless of order, it seems to me to be a
command too sophisticated for automation as a single action: "make the
target identical to the source, EXCPET ignore any files named bar.txt in
both the source and the target".

BTW, is COPY on your system an alias by any chance?
--
Steve
 
#3
Deleting of all hidden files from the target that are absent in the source,
hidden ones included, is what I'd expect /w to achieve. As to the second
case, it has incorrect syntax (the file exclusion option is supposed to
precede the /w option), but regardless of order, it seems to me to be a
command too sophisticated for automation as a single action: "make the
target identical to the source, EXCPET ignore any files named bar.txt in
both the source and the target".

BTW, is COPY on your system an alias by any chance?
COPY is not an alias on my system. Putting the exclusion in the correct place doesn't change the behavior.

I don't see why you think it is too sophisticated. I'm just saying that I would expect COPY to use the same criteria to select files to operate on in both the source and the target. I find it rather surprising that a command would delete a file that has the hidden, system, and read-only attributes without my specifying an /a: option.
 

rconn

Administrator
Staff member
May 14, 2008
10,096
85
#4
> I don't see why you think it is too sophisticated. I'm just saying that
> I would expect COPY to use the same criteria to select files to operate
> on in both the source and the target. I find it rather surprising that
> a command would delete a file that has the hidden, system, and read-
> only attributes without my specifying an /a: option.
This is WAD. If you want to sync your hidden & system files too, use the
/A:... option.

Rex Conn
JP Software
 
#5
This is WAD. If you want to sync your hidden & system files too, use the
/A:... option.
I'm sorry, but I don't follow. I don't want to sync hidden/system files. In particular I don't want to delete such files in the target directory. Is there a way to do that? copy /a:-h /w still deletes hidden files.

C:\Junk>dir /a

Volume in drive C is OS Serial number is 1ce5:1203
Directory of C:\Junk\*

3/07/2010 12:39p DIR .
3/07/2010 12:39p DIR ..
0 bytes in 0 files and 2 dirs
201,156,771,840 bytes free

C:\Junk>mkdir S

C:\Junk>mkdir T

C:\Junk>T\

C:\Junk\T>touch /c Foo.txt & attrib +h Foo.txt
3/07/2010 12:40:39.945 C:\Junk\T\Foo.txt
___A________I -> _H_A________I C:\Junk\T\Foo.txt

C:\Junk\T>cd ..

C:\Junk>copy /w S\* T\
Deleting C:\Junk\T\Foo.txt
1 file deleted
TCC: (Sys) There are no more files.
"C:\Junk\S\*"
0 files copied

C:\Junk>dir /a T\*

Volume in drive C is OS Serial number is 1ce5:1203
Directory of C:\Junk\T\*

3/07/2010 12:40p DIR .
3/07/2010 12:40p DIR ..
0 bytes in 0 files and 2 dirs
201,156,771,840 bytes free

C:\Junk>T\

C:\Junk\T>touch /c Foo.txt & attrib +h Foo.txt
3/07/2010 12:41:15.749 C:\Junk\T\Foo.txt
___A________I -> _H_A________I C:\Junk\T\Foo.txt

C:\Junk\T>cd ..

C:\Junk>copy /a:-h /w S\* T\
Deleting C:\Junk\T\Foo.txt
1 file deleted
TCC: (Sys) There are no more files.
"C:\Junk\S\*"
0 files copied

C:\Junk>dir /a T\*

Volume in drive C is OS Serial number is 1ce5:1203
Directory of C:\Junk\T\*

3/07/2010 12:41p DIR .
3/07/2010 12:41p DIR ..
0 bytes in 0 files and 2 dirs
201,156,771,840 bytes free
 

rconn

Administrator
Staff member
May 14, 2008
10,096
85
#6
> ---Quote (Originally by rconn)---
> This is WAD. If you want to sync your hidden & system files too, use
> the /A:... option.
> ---End Quote---
> I'm sorry, but I don't follow. I don't want to sync hidden/system
> files. In particular I don't want to delete such files in the target
> directory. Is there a way to do that? copy /a:-h /w still deletes
> hidden files.
/W is a sync; but you apparently don't really want to sync your directories;
you just want to *mostly* sync your directories, but excluding some files.
Unfortunately, there isn't any "mostly sync" option in COPY.

You should probably be using /C or /U instead of /W.

Rex Conn
JP Software
 
#7
/W is a sync; but you apparently don't really want to sync your directories; you just want to *mostly* sync your directories, but excluding some files. Unfortunately, there isn't any "mostly sync" option in COPY.

You should probably be using /C or /U instead of /W.
A "mostly sync" option would be nice, but I can live without it. However, philosophically, I wouldn't expect any command to delete hidden/system/read-only files unless this was clearly documented. I suggest updating the Help for /W.

By the way, I'm actually using "/U /W", but I didn't include the /U in my examples, since it didn't seem relevant.
 
#9
The /U is useless in this context, as /W will override it.
So, /W actually copies all files from the source to the destination, then deletes all files in the destination that aren't in the source. Correct?

I don't think the Help makes that clear. Also, it seems like in some cases there could be quite a bit of needless copying when syncing.

Is there a simple way to do a "copy /e /h /q /Nj /s /u Dir1\ Dir2\", then (or at the same time) delete files in the destination tree that aren't in the source?
 

dim

Dimitry Andric
May 31, 2008
203
0
Netherlands
#10
On 2010-03-07 21:28, David Marcus wrote:

> ---Quote (Originally by rconn)---
> The /U is useless in this context, as /W will override it.
> ---End Quote---
> So, /W actually copies all files from the source to the destination, then deletes all files in the destination that aren't in the source. Correct?
No, the COPY command *itself* copies all files from the source to the destination. :) The /W switch just modifies its behaviour.



> I don't think the Help makes that clear. Also, it seems like in some cases there could be quite a bit of needless copying when syncing.
Quoting the help file:

"/W Delete files in the target directory that don't exist in the source directory."

What is not clear about that?



> Is there a simple way to do a "copy /e /h /q /Nj /s /u Dir1\ Dir2\", then (or at the same time) delete files in the destination tree that aren't in the source?
Yes, use /W, and add the /A: option, as multiple people already told you in this thread. :)
 
#11
Quoting the help file:

"/W Delete files in the target directory that don't exist in the source directory."

What is not clear about that?
That copy ignores /U when you do that. I assume options can be combined unless the Help says otherwise.

Yes, use /W, and add the /A: option, as multiple people already told you in this thread. :)
Maybe you didn't notice the "/u" in what I wrote. In other words, do a one-way sync, but if most files are identical (as judged by the timestamp), skip the extra time needed to copy all the identical ones.
 
#12
Does /W cause copy to first delete everything in the target directory, then do the copy? I.e., is it just a delete followed by a copy? If so, then I understand why you can't combine /W and /U.

Suggested Help text:

/W Delete files in the target directory (including hidden and system, but not read-only files) that don't exist in the source directory. If used with /U, the /U option will be ignored.
 
#13
Hi,

with the latest version of TCMD x32 I have the following effect:

I usually have set the background of my TCC window to blue using OPTION.
While without these settings TCC/LE and TCC x64 come up with a black
background, TCC x32 comes up blue. I don't know where this blue comes
from, I find nothing in the INI files which could be responsible. What
is irritating me is that this blue is of a lighter hue than the blue I
get from the OPTION settings.

Speaking of OPTION: on the first tab of Take Command Options (Window?)
in my german version the next to last entry (Datei automatisch .......)
is cut of by the frame line.

TCMD x64: the installer still shows no license info.

There's another option to set background colors on the second tab
(Tabs?) of the Take Command Options: Fenster (Windows?). But whatever I
set the output colors to, even using admin rights, these setting come up
(Default) after a restart.

Best Regards,

* Klaus Meinhard *
<www.4dos.info>
 
#14
It seems that /U and /W can be combined. And, it seems that the files are deleted before the copying is done, but only the files that need to be deleted are deleted, not the entire directory:

C:\Junk>dir

Volume in drive C is TI105444W0C Serial number is 709c:de9d
Directory of C:\Junk\*

3/11/2010 12:34p DIR .
3/11/2010 12:34p DIR ..
0 bytes in 0 files and 2 dirs
271,641,681,920 bytes free

C:\Junk>ver /r

TCC 11.00.43 x64 Windows 7 [Version 6.1.7600]
TCC Build 43 Windows 7 Build 7600
Registered to davidmarcus - 1 System License

C:\Junk>mkdir S

C:\Junk>mkdir T

C:\Junk>touch /c S\Foo.txt
3/11/2010 12:35:21.844 C:\Junk\S\Foo.txt

C:\Junk>copy /s /w S\ T\
C:\Junk\S\Foo.txt => C:\Junk\T\Foo.txt
1 file copied

C:\Junk>copy /s /w S\ T\
C:\Junk\S\Foo.txt => C:\Junk\T\Foo.txt
1 file copied

C:\Junk>copy /s /u /w S\ T\
0 files copied

C:\Junk>touch /c T\A.txt
3/11/2010 12:37:47.923 C:\Junk\T\A.txt

C:\Junk>touch /c T\Z.txt
3/11/2010 12:37:59.810 C:\Junk\T\Z.txt

C:\Junk>copy /s /w S\ T\
Deleting C:\Junk\T\A.txt
Deleting C:\Junk\T\Z.txt
2 files deleted
C:\Junk\S\Foo.txt => C:\Junk\T\Foo.txt
1 file copied