Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
move

Reply  
Thread Tools
workhard's Avatar
Junior Member with 4 posts.
 
Join Date: Aug 2009
Experience: Intermediate
10-Aug-2009, 09:08 PM #1
Smile move
Hi,

Want to move the files(*.Doc and *.dot) from multiple level of folders to one folder and limit to copy 7,000 files each time?

From:
C:\Temp\CL\a
C:\Temp\CL\b
C:\Temp\CL\c
C:\Temp\DL\a
.....


To:
C:\Destination\


How to write in batch file??


Behind, copy all the latest file (duplication) and filename should not contain(~abc.doc).



Thanks,
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
11-Aug-2009, 02:30 AM #2
Welcome to TSG!

So you want to move all *.doc and *.dot files that are in any folder/subfolder under C:\Temp to C:\Destination
You don't want to move more than 7000 files at a time.

Are there other files in these folders, say *.txt or *.mp3?
Do you want to delete the folders afterwards if they are empty?
Could there be duplicate file names? If so, how would you want to handle that?
  • Overwrite the existing file?
  • Rename the 2nd and subsequent files? If so, using what format?
    1. Add a number to the end of the name
    2. Add Copy (x) of to the beginning of the name
    3. Something else
Quote:
Originally Posted by workhard View Post
Behind, copy all the latest file (duplication) and filename should not contain(~abc.doc).
I'm not clear on just what you mean by this.
Do you mean after the files have been moved to C:\Destination, you want to make a copy of all the files? Where will these copies be placed?
By "not contain ~abc.doc", does that mean files named exactly ~abc.doc are not allowed, or just filenames ending with ~abc.doc.
Example, File~abd.doc is not allowed but ~abcFile.doc is allowed.
Or do you mean that *.doc files cannot contain ~abc anywhere in the filename, so neither of the above would be allowed, and File~abcTest.doc would also not be allowed?
If a file with that name is found, should it just be deleted, or renamed to something else?

Here's a start until we get the details ironed out.
This will move all *.doc and *.dot files from every folder under C:\Temp to C:\Destination. If there is a duplicate name, it will prompt if you want to overwrite. Note that the All choice won't work, you will be prompted for each duplicate.
Code:
@Echo Off
SetLocal EnableDelayedExpansion
Set _Source=C:\Temp
Set _Dest=C:\Destination
Set _MaxToMove=7000
If NOT Exist %_Dest% MD %_Dest%
PushD %_Source%
Set _Count=0
For /F "Tokens=* Delims=" %%A in ('Dir /A-D /B /S *.dot *.doc') Do (
  Move /-Y "%%A" "%_Dest%"
  Set /A _Count+=1
  If !_Count!==%_MaxToMove% Echo Have moved !_Count! Files, quiting&Goto _Max
)
:_Max
PopD
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

workhard's Avatar
Junior Member with 4 posts.
 
Join Date: Aug 2009
Experience: Intermediate
11-Aug-2009, 10:35 PM #3
Hi,


Great I got that working perfect. However, I want to move those "~abc.doc" (filename start with ~) to "c:\destination\check" folder.

The rest of non word document move to "C:\destination\non-word" folder.

Can you tell me how from your code?



Thanks,
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
12-Aug-2009, 02:26 AM #4
This will check each file name for both .doc and .dot files to see if it starts with a tilde (~). This file will be included in the count.
If by non-word documents you mean files with extensions other than .doc or .dot, that will get a bit more complicated.
I'm guessing you want the non-word files to be included in the 7000 file limit.
Code:
@Echo Off
SetLocal EnableDelayedExpansion
Set _Source=C:\Temp
Set _Dest=C:\Destination
Set _MaxToMove=7000
If NOT Exist %_Dest% MD %_Dest%
If NOT Exist %_Dest%\Check MD %_Dest%\Check
If NOT Exist %_Dest%\non-word MD %_Dest%\non-word
PushD %_Source%
Set _Count=0
For /F "Tokens=* Delims=" %%A in ('Dir /A-D /B /S') Do (
  Set _tname=%%~nA
  Set _text=%%~xA
  Set /A _Count+=1
  Set _Wfile=0
  If /I NOT "!_text!"==".doc" If /I NOT "!_text!"==".dot" Set _WFile=1
  If !_Wfile!==1 (
    Move /-Y "%%A" "%_Dest%\non-word"
  ) Else (
    If "!_tname:~0,1!"=="~" (
      Move /-Y "%%A" "%_Dest%\Check"
    ) Else (
      Move /-Y "%%A" "%_Dest%"
))
If !_Count!==%_MaxToMove% Echo Have moved !_Count! Files, quiting&Goto _Max
)
:_Max
PopD
Note that the batch file cannot be in C:\Temp or any of it's subfolders, or it will also get moved. Which will cause it to fail with a The batch file cannot be found. message.
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

workhard's Avatar
Junior Member with 4 posts.
 
Join Date: Aug 2009
Experience: Intermediate
17-Aug-2009, 01:11 AM #5
Hi,

Great and great. I got that work as well. Now, I want to sort the filename which contain *-cl* into the destination\cl\ folder.


Where should I add the code and what code I should add?


Thanks
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
17-Aug-2009, 03:57 AM #6
Need more information to figure that out.
If the filename contains -cl and also starts with ~ does it get moved to Destination\Check or Destination\cl?
If it contains -cl and is not .doc or .dot, does it go to Destination\non-word or Destination\cl?

Searching a filename for a particular string that occurs anywhere in the name would require using findstr, which will slow this down considerably. It may be faster to use DIR to find those files first. But if you have more than 7000 of those files, nothing else would be processed on the first run.

Sounds like you need to setup a table with all the conditions you want to check for, and the desired result, something like this
Code:
             |                    Condition                    |
             |  Does not contain -cl  |      Contains -cl      |
  Extension  |   Starts   |  Starts   |   Starts   |  Starts   |
             |   with ~   | without ~ |   with ~   | without ~ |
Ext is .doc  | Dest\Check |   Dest    | Dest\Check |  Dest\CL  |
Ext is .dot  | Dest\Check |   Dest    | Dest\Check |  Dest\CL  |
Ext is .*    | Dest\Nwrd  | Dest\Nwrd |  Dest\CL   |  Dest\CL  |
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

workhard's Avatar
Junior Member with 4 posts.
 
Join Date: Aug 2009
Experience: Intermediate
17-Aug-2009, 09:45 PM #7
Hi,


Easy, as what I started first, get all the "~*" file (with or without cl) into the Destination\check and non word document(with or without cl) will be in destination\non-word folder.

Next, if the filename contain -cl will be in the destination\cl folder and the rest will be in destination folder.

Code:
| Condition |
| Does not contain -cl | Contains -cl |
Extension | Starts | Starts | Starts | Starts |
| with ~ | without ~ | with ~ | without ~ |

Ext is .doc | Dest\Check | Dest | Dest\Check | Dest\CL |
Ext is .dot | Dest\Check | Dest | Dest\Check | Dest\CL |
Ext is .* | Dest\Nwrd | Dest\Nwrd | Dest\Nwrd | Dest\Nwrd |


Thanks,
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
19-Aug-2009, 04:22 AM #8
The added code is shown in DarkRed and bold. Also added a line to indicate that all files were moved. It's not case sensitive, so both -CL and -cl (or any combination of case) will be found.
This moves all files that are not .doc or .dot to the non-word folder, whether or not they start with ~ or contain -cl. The first file also did not check for ~ on non-word files.
Code:
@Echo Off
SetLocal EnableDelayedExpansion
Set _Source=C:\Temp
Set _Dest=C:\Destination
Set _MaxToMove=7000
If NOT Exist %_Dest% MD %_Dest%
If NOT Exist %_Dest%\Check MD %_Dest%\Check
If NOT Exist %_Dest%\non-word MD %_Dest%\non-word
If NOT Exist %_Dest%\CL MD %_Dest%\CL
PushD %_Source%
Set _Count=0
For /F "Tokens=* Delims=" %%A in ('Dir /A-D /B /S') Do (
  Set _tname=%%~nA
  Set _text=%%~xA
  Set /A _Count+=1
  Set _Wfile=0
  If /I NOT "!_text!"==".doc" If /I NOT "!_text!"==".dot" Set _WFile=1
  If !_Wfile!==1 (
    Move /-Y "%%A" "%_Dest%\non-word"
  ) Else (
    If "!_tname:~0,1!"=="~" (
      Move /-Y "%%A" "%_Dest%\Check"
    ) Else (
      Echo %%~nA|Findstr /I /C:"-cl">Nul
      If !ERRORLEVEL!==1 (
       Move /-Y "%%A" "%_Dest%"
      ) Else (
       Move /-Y "%%A" "%_Dest%\CL"
)))
If !_Count!==%_MaxToMove% Echo Have moved !_Count! Files, quiting&Goto _Max
)
Echo Moved !_Count! Files. All Files moved
:_Max
PopD
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:28 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.