Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use this batch file to find and move files... but it does not work on hidden files. What's missing?

@echo off
set root=E:\backup
set dest=E:\Tmp
for /f "delims=" %%f in ('dir /ad /b /s %root%') do @move "%%f\~$*.SLD*" %dest%
share|improve this question
for one thing, the /ad switch tells dir to only list directories. – EBGreen May 8 '12 at 20:23
I don't really understanding the filename part. What would ~$*.SLD* resolve to? – paradroid May 8 '12 at 21:14
@ENGreen: That looks intended. The /B switch lists the results as basic paths, with no additional info. Each result is parsed as the variable %%f in the for command – abstrask May 8 '12 at 21:47
@paradroid: "~$" [Some or no characters] ".sld" [Some or no characters] I guess? – abstrask May 8 '12 at 21:47
joe, is removing the hidden attribute an option? – abstrask May 8 '12 at 21:51

You're going to have to unhide the files anyway, because move won't work on a file that it can't find (even if you supply the full filename). There's no flag to give to move to get it to look for files tagged with the hidden attribute.

Unhide the files with attrib -h. Replace your for line with this set :

for /f "delims=" %%f in ('dir /ad /b /s %root%') do (
  @attrib -h "%%f\~$*.SLD*"
  @move "%%f\~$*.SLD*" %dest%

You could use a more sophisticated tool, like xcopy or robocopy, that can operate on hidden files. Of course, these are copy tools, so you'll still have to unhide the original files and delete them after the copy finishes.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .