Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
setlocal
set root=E:\backup
set dest=E:\Tmp
for /f "delims=" %%f in ('dir /ad /b /s %root%') do @move "%%f\~$*.SLD*" %dest%
endlocal
share|improve this question
1  
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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.