How to search and move the files to another folder

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

zadrian

Thread Starter
Joined
Dec 1, 2011
Messages
5
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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

Thread Starter
Joined
Dec 1, 2011
Messages
5
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.
 
Joined
Dec 1, 2011
Messages
17
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.

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

zadrian

Thread Starter
Joined
Dec 1, 2011
Messages
5
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Then you need to use the DIR command inside your For loop. The DIR command will output hidden files.
Code:
FOR /F "tokens=*" %%a in ('dir /b /a-d /s *.xls') do copy "%%~a" c:\xls
 

zadrian

Thread Starter
Joined
Dec 1, 2011
Messages
5
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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

Thread Starter
Joined
Dec 1, 2011
Messages
5
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top