# How to search and move the files to another folder



## zadrian (Dec 2, 2011)

Hi, I need some advise and help on batch file to search folders for file types and move them into another folder.

One example is that we might have excel files all over, from downloads using different browsers, desktop, my documents & probably any folder a user creates especially "new folder".

I used to create a batch file using the "for" command running a "dir" looking for "*.xls" and then a "move %% c:\xls".
Can someone kndly assist


----------



## Squashman (Apr 4, 2003)

zadrian said:


> I used to create a batch file using the "for" command running a "dir" looking for "*.xls" and then a "move %% c:\xls".
> Can someone kndly assist


Lets see the batch file you have written already.


----------



## zadrian (Dec 2, 2011)

Thats the problem, I wrote it a few years back and when the hdd died, I had to re-install the O/S....I lost the file.


----------



## BrennaKessler (Dec 1, 2011)

There are more than one ways to manage your files on the Android phones. The easiest way is to connect the phone to your PC through a USB cable and you will be able to explore its storage media with your mouse. That way, you can create folders, drag files and copy paste different items.


----------



## Squashman (Apr 4, 2003)

BrennaKessler said:


> There are more than one ways to manage your files on the Android phones.


This question has nothing to do with an Android phone. Why are you posting in this thread.


----------



## Squashman (Apr 4, 2003)

I hope you realize you don't want to run this from the root of the C: drive. You will end up with errors because you would be trying to copy the file onto itself.


```
for /r %%a in (*.xls) do copy "%%~a" c:\xls
```


----------



## zadrian (Dec 2, 2011)

thanks....the command worked. But is there a way to make it work in hidden folders (such as user\appdata) ?

Is there a command to move folders of a name too ?


----------



## Squashman (Apr 4, 2003)

Then you need to use the DIR command inside your For loop. The DIR command will output hidden files.

```
FOR /F "tokens=*" %%a in ('dir /b /a-d /s *.xls') do copy "%%~a" c:\xls
```


----------



## zadrian (Dec 2, 2011)

what is the meaning of "tokens=*" ? Anyway i got a cannot fine the file specified.....somehow i got access denied.

i can use windows explorer to move or delete the file but not in DOS mode or batch file....


----------



## Squashman (Apr 4, 2003)

By default, the For loop will take each line of input and split the line up into Tokens (variables). It does this by using a SPACE and TAB as the delimiter. So if any of your file names have spaces in them the file name would get split up between multiple tokens (Variables). The first portion would be put into %%A and the 2nd portion would go into %%B and so on depending on how many spaces are in your file name. You don't want this to happen. You want the entire file name to be assigned to the %%A variable.

I have no idea why you are getting that error. You need to run the batch file from the cmd prompt and show me the exact output. Copy and paset the output to the forums.

Also need to know which version of Windows you are running.


----------



## zadrian (Dec 2, 2011)

Thanks for your help...the batch works...it was my bad....started with %%a but ended with a %a....

The issue was with the person behind the keyboard...


----------



## Squashman (Apr 4, 2003)

zadrian said:


> Thanks for your help...the batch works...it was my bad....started with %%a but ended with a %a....
> 
> The issue was with the person behind the keyboard...


What's wrong with copy and paste?
I tell this to my programmers at work all the time. I can't tell you how many mistakes I see by my programmers because they didn't copy and paste the instructions I gave to them.


----------

