Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

expected behavior of move /sx

Feb
240
3
Here's the case. I have a folder (folder1) containing a few folders (folder2, folder3), each with a few files, and I'd like to bring all of the files into folder1. The command for this is of course:
move /sx *.* .
This command works, but there were two surprises:
1] In addition to moving the files, "move /sx" also deleted the subfolders (folder2, folder3). This does make sense, but it is not what I expected from a move command (the documentation for move /sx doesn't mention anything about this).
The illogic of this behavior comes to the fore when moving only some files. With folder2 and folder3 both containing some .txt files and some .doc files, I executed the following:
move /sx *.txt .
After moving the files, TCC reports:
"removing folder2", and "removing folder3"
Obviously, it does not actually remove these folders, because there are .doc files left in them. But the fact that it reports that it is attempting to remove them seems problematic, since the user certainly does not want that to happen in this case.

2] With the same scenario, but with some files in the root folder (folder1) as well, I ran the command:
move /sx *.* .
Here the command refused to budge, aborting with a message that it cannot move a file onto itself. And here I have two questions:
2a] I understand why it reports this error, but I would have expected it to continue anyway with the rest of the files. Is there any way to tell MOVE to ignore such errors and continue with the next file, rather than aborting?
2b] I worked around the problem by running:
move /S+1 /SX *.* .
However, here I found something weird. If I tried to move just the .txt files, with:
move /S+1 /SX *.txt .
It didn't work at all, reporting "0 files moved".
That is, with identical directory structures, and with a few .txt files and .doc in the subfolders, the command "move /s+1 /sx *.txt" did not succeed in moving any .txt files, but "move /s+1 /sx *.* ." did succeed in moving all of the files, including the .txt files. Why should this be?
 
Hi Rex,
OK, but wouldn't it make sense to do this only if the source directories have been emptied? The line "removing folderX" can be scary for a user who still has important things in folderX, even if the remove won't actually be executed.
A few remaining questions:
1] As I noted, "move /S+1 /SX *.txt ." did not work on my machine at all. Am I doing something wrong?
2] Also, as I asked above, how can I instruct move/copy to continue on error rather than aborting? (Specifically with regard to the "cannot move file onto itself", which causes MOVE to abort).
3] What does WAD mean?
Thanks,
Avi

WAD - MOVE /S or /SX always tries to remove source directories.

The text in the help was copied from the COPY /SX option; I'll update it to make it clear that it's a MOVE, not a COPY.
 
Hi Rex,
OK, but wouldn't it make sense to do this only if the source directories have been emptied? The line "removing folderX" can be scary for a user who still has important things in folderX, even if the remove won't actually be executed.

I could do that, but it would double the time required to do the MOVE. TCC would have to examine the directory tree before it attempted to remove each directory, and most people (like you!) complain more about the time spent in a command.

1] As I noted, "move /S+1 /SX *.txt ." did not work on my machine at all. Am I doing something wrong?

You cannot combine multiple /S options a single MOVE command.

2] Also, as I asked above, how can I instruct move/copy to continue on error rather than aborting? (Specifically with regard to the "cannot move file onto itself", which causes MOVE to abort).

MOVE /Ne will continue on non-critical errors. However, that error is considered a critical error, and IMO probably means that any remaining MOVE attempts will fail or (worse) be simply wrong.

3] What does WAD mean?

Working As Designed.
 
Hi Rex,
OK, I accept that MOVE /SX will always attempt to remove the directories, as you explained. WAD.
Regarding your other comments, however, I remain perplexed, for two reasons:

1] You note that /S+1 cannot be combined with /SX, and you also note that moving a file onto itself will always be considered a critical error and abort an operation (that is, it cannot be ignored by /Ne). If I understand correctly, this means that I cannot use a MOVE command to accomplish the task that I set out to accomplish.
Namely: if I have a root folder (folder1) that has a few files, and beneath it there are a series of other folders (folder2, folder3, etc.) that contain additional files, and I want to move all of the files from the subfolders into the root folder (folder1), I cannot do so. I would have thought that I could accomplish this with the command:
MOVE /SX *.* .
However:
(a) This will abort upon encountering the files within the root folder itself.
(b) There is no way to continue after the abort because that error is considered a critical error.
(c) I cannot tell it to skip the root level files with /S+1 because /SX and /S+1 cannot be combined.

Based on my example here, it seems to me that this error should *not* be considered a critical error, because this example demonstrates a valid case in which one would want to skip over the error and continue.
Furthermore, I believe that this example demonstrates ample need for use of the /S+x switch together with the /SX switch.

2] The second reason I remain perplexed is that, as I noted in my initial email, the command
MOVE /S+1 /SX *.* .
does in fact obviate the problem. That is, although you've stated that /S+x and /SX cannot be combined, it does do the job for me in this case - if I just say "MOVE /SX *.*", it aborts, but if I write "MOVE /S+1 /SX *.*", it ignores the files in the root folder, and moves all the files from the subfolders to the root.
Unfortunately, though, this only seems to work with "*.*" If I use "*.txt" instead of "*.*", it doesn't work at all. So what is going on here?
 
Namely: if I have a root folder (folder1) that has a few files, and beneath it there are a series of other folders (folder2, folder3, etc.) that contain additional files, and I want to move all of the files from the subfolders into the root folder (folder1), I cannot do so.

You could do it in two steps: Move the files somewhere else, then move them to the root folder.
 
You cannot combine /S+n and /SX, period. It may appear to work, in some directories and in some circumstances, but it will definitely fail (and possible cause mayhem) in others. The MOVE command absolutely does not provide for it.

If you want to request this as a new feature in a future version, click on the "Feedback" tab.
 
You cannot combine /S+n and /SX, period. It may appear to work, in some directories and in some circumstances, but it will definitely fail (and possible cause mayhem) in others.

OK, I'll post it as a feature request (at least, to have a switch which is equivalent to /SX but which ignores files in the root directory, even if the full /S+ isn't supported together with /SX), because I believe it is a very useful feature.

However, your statement that using /S+ together with /SX may "cause mayhem" is very unsettling. First of all, the documentation does not specify that these two cannot be used together (it notes that /SX "implies" /S, but nothing more), and it seemed to me, after reading the documentation, that in my situation the use of those two switches together would be the relevant thing to do in order to solve my problem. Yet now we are told that what seemed like a legitimate solution actually could have caused "mayhem" within the file system. Indeed, even if the documentation is altered to include a severe warning about the /S+ /SX combo, it seems to me that if it is in danger of causing mayhem, it should be blocked within the program itself. Wouldn't you agree?
 
I have found an adequate solution to this issue (specifically, the question of how can one flatten a directory, moving all files from the various subdirectories into the base folder, although some already files exist in the base folder).

First a recap:
1] As explained above, "move /sx" cannot do the job, because it fails on the files in the base folder, and because the files in the base folder cannot be excluded with "/S+1".
2] David Marcus's suggestion of moving the files elsewhere was possible, but it was predicated on an existing empty folder, which I didn't want to have to assume.
3] I also tried using EXCEPT, like this:
EXCEPT (*.*) move /sx *.* .
This also failed, though, because it turns out that EXCEPT excludes subdirectories as well as files.

However, taking my cue from the operation of the EXCEPT command, I found that could use the ATTRIB command to easily hide all files without hiding the subdirectories (this is the default behavior of ATTRIB *), and so we can accomplish the stated goal with a three line batch file as follows:
attrib *.* +h
move /sx *.* .
attrib *.* -h
 
Avi, please see my posting about this issue your suggestion in the Facebook (now equivalent) of the "Suggestions" forum. Again, problem is completely solved, and quite easily, I think. - Dan
 
Dave - Yes, you are correct that the unhiding of previously hidden files in the base directory would be a negative side-effect of my proposed solution (just as would happen with any use of the EXCEPT command, I believe).

Dan - Thanks so much for pointing out the usefulness of the /O option for my case!
Indeed, now that you pointed it out (and as I've noted on the Suggestion forum), I've found that I can accomplish the whole thing with a single command, even without the "for" loop, by using the /O switch together with the /SX switch, because /O prevents the "cannot move file to itself" error on which TCC would otherwise abort the operation:
move *.* . /SX /O
I appreciate your help! As you note, "problem is completely solved, and quite easily".
 
Avi, please see my posting about this issue your suggestion in the Facebook (now equivalent) of the "Suggestions" forum. Again, problem is completely solved, and quite easily, I think. - Dan

I've been reading the "What's New?" messages that have been posted since I last visited the forums. In two different threads, you've posted something like this; basically, "go see my other post". Could you add a link to that post so we don't have to try to hunt it down? Thanks.
 
Hi JohnQSmith,
See here:
uservoice.com/forums/94009-take-command/suggestions/2665235-add-command-to-flatten-files-in-directory-structur
- Avi

I've been reading the "What's New?" messages that have been posted since I last visited the forums. In two different threads, you've posted something like this; basically, "go see my other post". Could you add a link to that post so we don't have to try to hunt it down? Thanks.
 

Similar threads

Back
Top