2 Batches required

H

happytoday

I need to automate those 2 tasks :
1-Distribute number of files inside 1 directory to subdirectories
created each one include only 1000 file. All of them named
1,2,3...etc.
2-compare names of files inside 2 directories and see the different of
files .
Please help .
Thanks in advance .
 
P

Pegasus \(MVP\)

happytoday said:
I need to automate those 2 tasks :
1-Distribute number of files inside 1 directory to subdirectories
created each one include only 1000 file. All of them named
1,2,3...etc.
2-compare names of files inside 2 directories and see the different of
files .
Please help .
Thanks in advance .

Try this:
1. Copy and paste the lines below into c:\Windows\happy.bat.
2. Adjust Line #05 to suit your environment.
3. Remove all line numbers.
4. Run the batch file.
5. If you're happy with the result you see on the screen, remove
the word "echo" from Lines #12 and #13.

I do not understand what you're trying to achieve with your second
question. Please elaborate.

01. @echo off
02. set limit=1000
03. set count=0
04. set DirName=1
05. set source=d:\Thu
06.
07. setlocal enabledelayedexpansion
08. dir /b "%source%\*.txt" > c:\dir.txt
09.
10. echo Moving files from "%Source%" to "%Source%\%DirName%"
11. for /F "tokens=*" %%* in (c:\dir.txt) do (
12. if not exist "%Source%\!DirName!" echo md "%Source%\!DirName!"
13. echo move "%Source%\%%*" "%Source%\!DirName!"
14. set /a count=!count! + 1
15. if !count! GEQ %limit% (
16. set count=0
17. set /a DirName=!DirName! + 1
18. echo Moving files from "%Source%" to "%Source%\!DirName!"
19. )
20. )
21. del c:\dir.txt
 
T

Todd Vargo

happytoday said:
I need to automate those 2 tasks :
1-Distribute number of files inside 1 directory to subdirectories
created each one include only 1000 file. All of them named
1,2,3...etc.
2-compare names of files inside 2 directories and see the different of
files .
Please help .
Thanks in advance .

We will be glad to HELP you. So that we are not doing all of your work for
you, show us what you have written so far.
 
T

Tom Lavedas

We will be glad to HELP you. So that we are not doing all of your work for
you, show us what you have written so far.

Well - I know where you're coming from, but my biggest problem is that
the problems are pretty loosely defined - maybe an English as a second
(or third) language issue.

The second one is pretty easy to write, but hard to imagine for a less
than intermediate batch writer, so I took a crack (using NT/2K/XP/
Vista(?) approach) ...

@echo off
set fldr1="D:\Folder 1"
set fldr2="X:\Folder 2"
for %%A in (%fldr1%\*.*) do (
if not exist %fldr2%\%%~nxA (
echo %%~nxA in %fldr1% and NOT in %fldr2%)
)
)
for %%A in (%fldr2%\*.*) do (
if not exist %fldr1%\%%~nxA (
echo %%~nxA in %fldr2% and NOT in %fldr1%)
)
)

This can be done in no NT variant OSs, need to forgo the use of the
parentheses and CD into the folder under test before each of the FOR
statements. If the folders are on different drive it requires another
trick or two. But I leave that to a follow up (if there is one).

I didn't touch the first one without OPs input (code and or more
explanation of what is trying to be accomplished.)

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
F

foxidrive

I didn't touch the first one without OPs input (code and or more
explanation of what is trying to be accomplished.)

I figure the OP wants a series of folders inside the current folder named
1,2,3,4...n that each contain 1000 files. The files are to be moved from
the current folder.
 
T

Todd Vargo

foxidrive said:
I figure the OP wants a series of folders inside the current folder named
1,2,3,4...n that each contain 1000 files. The files are to be moved from
the current folder.

Sounds about right but ISTM is a easily handled(manually) one time
operation.
 
R

Richard Bonner

The second one is pretty easy to write, but hard to imagine for a less
than intermediate batch writer, so I took a crack (using NT/2K/XP/
Vista(?) approach) ...
@echo off
set fldr1="D:\Folder 1"
set fldr2="X:\Folder 2"
for %%A in (%fldr1%\*.*) do (
if not exist %fldr2%\%%~nxA (
echo %%~nxA in %fldr1% and NOT in %fldr2%)
)
)
for %%A in (%fldr2%\*.*) do (
if not exist %fldr1%\%%~nxA (
echo %%~nxA in %fldr2% and NOT in %fldr1%)
)
)
This can be done in no NT variant OSs, need to forgo the use of the
parentheses and CD into the folder under test before each of the FOR
statements. If the folders are on different drive it requires another
trick or two. But I leave that to a follow up (if there is one).
Tom Lavedas

*** Hmm, can't this be done in one line? I am thinking of something such
as:

FOR %%F IN (*.*) DO FC %%F path\%F


Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
 
T

Todd Vargo

Richard said:
*** Hmm, can't this be done in one line? I am thinking of something such
as:

FOR %%F IN (*.*) DO FC %%F path\%F

Only OP knows for sure what was meant by "compare names of files".

BTW, you have a % missing from the last %F. :O
 
H

happytoday

Try this:
1. Copy and paste the lines below into c:\Windows\happy.bat.
2. Adjust Line #05 to suit your environment.
3. Remove all line numbers.
4. Run the batch file.
5. If you're happy with the result you see on the screen, remove
    the word "echo" from Lines #12 and #13.

I do not understand what you're trying to achieve with your second
question. Please elaborate.

01. @echo off
02. set limit=1000
03. set count=0
04. set DirName=1
05. set source=d:\Thu
06.
07. setlocal enabledelayedexpansion
08. dir /b "%source%\*.txt" > c:\dir.txt
09.
10. echo Moving files from "%Source%" to "%Source%\%DirName%"
11. for /F "tokens=*" %%* in (c:\dir.txt) do (
12.   if not exist "%Source%\!DirName!" echo md "%Source%\!DirName!"
13.   echo move "%Source%\%%*" "%Source%\!DirName!"
14.   set /a count=!count! + 1
15.   if !count! GEQ %limit% (
16.     set count=0
17.     set /a DirName=!DirName! + 1
18.     echo Moving files from "%Source%" to "%Source%\!DirName!"
19.    )
20. )
21. del c:\dir.txt

I tried that a sample version but not working with me :

@echo off
set limit=2
set count=0
set DirName=1
set source=F:\etisalat\batches\data
set new=F:\etisalat\batches\new

setlocal enabledelayedexpansion
dir /b "%source%\*.txt" > %new%\dir.txt

echo Moving files from "%Source%" to "%Source%\%DirName%"
for /F "tokens=*" %%* in (%new%\dir.txt) do (
if not exist "%Source%\!DirName!" echo md "%Source%\!DirName!"
echo move "%Source%\%%*" "%Source%\!DirName!"
set /a count=!count! + 1
if !count! GEQ %limit% (
set count=0
set /a DirName=!DirName! + 1
)
)
echo Moving files from "%Source%" to "%Source%\!DirName!"
::del c:\dir.txt
 
H

happytoday

***   True. I took it to mean the differences of the contents of
like-named files.


***   Oh, so I did. Thanks for picking me up on that.

         Richard Bonnerhttp://www.chebucto.ca/~ak621/DOS/

I required in the second batch to compare name of files not contents
of file . When I tried FC command it compared contents like this :
F:\etisalat\batches>for %f in (F:\etisalat\batches\data\*.*) do fc %f
F:\etisalat\batches\new\*.*

F:\etisalat\batches>fc F:\etisalat\batches\data\1.txt F:\etisalat
\batches\new\*.
*
Comparing files F:\ETISALAT\BATCHES\DATA\1.txt and F:\ETISALAT\BATCHES
\NEW\1.txt

FC: no differences encountered


F:\etisalat\batches>fc F:\etisalat\batches\data\2.txt F:\etisalat
\batches\new\*.
*
Comparing files F:\ETISALAT\BATCHES\DATA\2.txt and F:\ETISALAT\BATCHES
\NEW\2.txt

FC: no differences encountered


F:\etisalat\batches>fc F:\etisalat\batches\data\3.txt F:\etisalat
\batches\new\*.
*
Comparing files F:\ETISALAT\BATCHES\DATA\3.txt and F:\ETISALAT\BATCHES
\NEW\3.txt

FC: no differences encountered


F:\etisalat\batches>fc F:\etisalat\batches\data\4.txt F:\etisalat
\batches\new\*.
*
Comparing files F:\ETISALAT\BATCHES\DATA\4.txt and F:\ETISALAT\BATCHES
\NEW\4.txt

FC: no differences encountered


But when I tried that batch below I got wrong results (wrong file
names not even exist in the folders mentioned in set statements
:
@echo off
set fldr1="F:\etisalat\batches\data"
set fldr2="F:\etisalat\batches\new"
for %%A in (%fldr1%\*.*) do (
if not exist %fldr2%\%%~nxA (
echo %%~nxA in %fldr1% and NOT in %fldr2%)
)
)
for %%A in (%fldr2%\*.*) do (
if not exist %fldr1%\%%~nxA (
echo %%~nxA in %fldr2% and NOT in %fldr1%)
)
)

Results:
:----------
data in "F:\etisalat\batches\data" and NOT in "F:\etisalat\batches
\new"
GOM PLAYEREN SETUP.EXE in "F:\etisalat\batches\data" and NOT in "F:
\etisalat\batches\new"
realalt182.exe in "F:\etisalat\batches\data" and NOT in "F:\etisalat
\batches\new"
new in "F:\etisalat\batches\new" and NOT in "F:\etisalat\batches
\data"
GOM PLAYEREN SETUP.EXE in "F:\etisalat\batches\new" and NOT in "F:
\etisalat\batches\data"
realalt182.exe in "F:\etisalat\batches\new" and NOT in "F:\etisalat
\batches\data"
 
P

Pegasus \(MVP\)

Try this:
1. Copy and paste the lines below into c:\Windows\happy.bat.
2. Adjust Line #05 to suit your environment.
3. Remove all line numbers.
4. Run the batch file.
5. If you're happy with the result you see on the screen, remove
the word "echo" from Lines #12 and #13.

I do not understand what you're trying to achieve with your second
question. Please elaborate.

01. @echo off
02. set limit=1000
03. set count=0
04. set DirName=1
05. set source=d:\Thu
06.
07. setlocal enabledelayedexpansion
08. dir /b "%source%\*.txt" > c:\dir.txt
09.
10. echo Moving files from "%Source%" to "%Source%\%DirName%"
11. for /F "tokens=*" %%* in (c:\dir.txt) do (
12. if not exist "%Source%\!DirName!" echo md "%Source%\!DirName!"
13. echo move "%Source%\%%*" "%Source%\!DirName!"
14. set /a count=!count! + 1
15. if !count! GEQ %limit% (
16. set count=0
17. set /a DirName=!DirName! + 1
18. echo Moving files from "%Source%" to "%Source%\!DirName!"
19. )
20. )
21. del c:\dir.txt

I tried that a sample version but not working with me :

@echo off
set limit=2
set count=0
set DirName=1
set source=F:\etisalat\batches\data
set new=F:\etisalat\batches\new

setlocal enabledelayedexpansion
dir /b "%source%\*.txt" > %new%\dir.txt

echo Moving files from "%Source%" to "%Source%\%DirName%"
for /F "tokens=*" %%* in (%new%\dir.txt) do (
if not exist "%Source%\!DirName!" echo md "%Source%\!DirName!"
echo move "%Source%\%%*" "%Source%\!DirName!"
set /a count=!count! + 1
if !count! GEQ %limit% (
set count=0
set /a DirName=!DirName! + 1
)
)
echo Moving files from "%Source%" to "%Source%\!DirName!"
::del c:\dir.txt

================

You write "I tried that a sample version but not working with me".
This doesn't tell me anything. Remember - I can't see your screen,
hence you need to be a lot more specific.

I also suggest you reply quickly. You started this thread five weeks
ago and it is about to disappear from my newsreader's horizon.
 
H

happytoday

Two errors: Your parentheses were mismatched
and for long filenames the "%%~nxA" term has to be double quoted
(this works below but the syntax that splits a path into multiple
double-quoted terms will not work with all Microsoft tools)

@echo off
  set fldr1="F:\etisalat\batches\data"
  set fldr2="F:\etisalat\batches\new"
  for %%A in (%fldr1%\*.*) do (
    if not exist %fldr2%\"%%~nxA" (
      echo %%~nxA in %fldr1% and NOT in %fldr2%
    )
  )
  for %%A in (%fldr2%\*.*) do (
    if not exist %fldr1%\"%%~nxA" (
      echo %%~nxA in %fldr2% and NOT in %fldr1%
    )
  )- Hide quoted text -

- Show quoted text -

divide.bat is working fine to me :
-----------
@echo off
set limit=2
set count=0
set DirName=1
set source=F:\etisalat\batches\data
set new=F:\etisalat\batches\new

setlocal enabledelayedexpansion
dir /b "%source%\*.txt" > %new%\dir.txt

echo Moving files from "%Source%" to "%new%\%DirName%"
for /F "tokens=*" %%* in (%new%\dir.txt) do (
if not exist "%Source%\!DirName!" md "%new%\!DirName!"
move "%Source%\%%*" "%new%\!DirName!"
:: if not exist "%Source%\!DirName!" echo md "%new%\!DirName!"
:: echo move "%Source%\%%*" "%new%\!DirName!"

set /a count=!count! + 1
if !count! GEQ %limit% (
set count=0
set /a DirName=!DirName! + 1
)
)
echo Moving files from "%Source%" to "%new%\!DirName!"
::del c:\dir.txt

But executing compare.bat results are wrong though the 2 directories
contains different files I got this :
F:\etisalat\batches>compare
data in "F:\etisalat\batches\data" and NOT in "F:\etisalat\batches
\new"
new in "F:\etisalat\batches\new" and NOT in "F:\etisalat\batches
\data"

I need to show the files that are in directory and in not in the other
directory .
compare.bat :
----------
@echo off
set fldr1="F:\etisalat\batches\data"
set fldr2="F:\etisalat\batches\new"
for %%A in (%fldr1%\*.*) do (
if not exist %fldr2%\"%%~nxA" (
echo %%~nxA in %fldr1% and NOT in %fldr2%
)
)
for %%A in (%fldr2%\*.*) do (
if not exist %fldr1%\"%%~nxA" (
echo %%~nxA in %fldr2% and NOT in %fldr1%
)
)


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top