1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How to search and move the files to another folder

Discussion in 'DOS/Other' started by zadrian, Dec 1, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. zadrian

    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
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Lets see the batch file you have written already.
     
  3. zadrian

    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.
     
  4. BrennaKessler

    BrennaKessler

    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.
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    This question has nothing to do with an Android phone. Why are you posting in this thread.
     
  6. Squashman

    Squashman 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
     
  7. zadrian

    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 ?
     
  8. Squashman

    Squashman 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
     
  9. zadrian

    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....
     
  10. Squashman

    Squashman 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.
     
  11. zadrian

    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...
     
  12. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    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.
     
  13. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1029298

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice