Compare too foldors

October 12, 2009 at 16:51:44
Specs: Windows XP
*sorry in the title> "too" means "two" my bad..
HI people!
I wrote a code that deleting a file from foldor B if it dont exist on A:
for /f "delims=" %%a in ('dir /b "D:\B"') do (
    if not exist "D:\A\%%a" del /Q "D:\B\%%a"

has you can see the %%a is the file name.
To make it more clear,
lets say that in foldor A we got:
And in foldor B we got:

The file 3.txt will be deleted.

NOW Here is my problem:
The code works fine on a simple directory
but if i try it on foldor with subdirectories
it wont do a thing..
How can i make it work on the subdirectories as well?

*I am very sorry about my english
i don't use to write so much...

See More: Compare too foldors

Report •

October 12, 2009 at 19:38:55
i can't write winXP batch script because my XP system is dead, but this might be the logic structure:

'path1 is the path you are using as the standard
'path2 is the one you want to "clean up"
cd path2
call foo
(that is:)
goto gtfo

for x in (dir /b /a:d) do
cd x
call foo
for y in (dir /b *.*) do
if not(exist) p1+"\"+y
del y
end if
cd ..
'much apologies, i KNEW that was too simple!
'the path-string manipulation much more gnarley:
'this is the gnarly part i didn't count on...
'base dir. of C for example: C:\uuu\bbb
'base dir of F (whatever, network drv) is: F:\y\z
'whatever locn of F, need to snip off "F:\y\z"
'from curr. locn ("CD") and repl
'with "C:\uuu\bbb" base path to test 'for 'existance.
'via a "dir /a:d /b" command or "if exist" test.
'get curr. fullpath on slave: can you do this?
set p=("cd")
'snip off the base
'is there such a thing as len()?
set n=len(path2)
'is such thing as mid (or substr, etc)
set p=mid(p,n+1,100)
'now stick it onto the master basepath
set p1=path1+p
'you can see why i am currently limited,
'but others in forum will know how to do
'this snip/cut/paste stuff.

if not (exist) p1+"\"+x
rd x
end if


i'm not sure if this would work, i don't have the equipment
to try it or the syntax knowledge to write it. the idea is
that "foo" keeps calling itself until it reaches the periphery
of the tree structure, then starts conditionally deleteing
all the files not on drive C of the same name and path.
the "rd" (rmdir, remove directory) is not conditional cause
i couldn't think of a quick and easy way to see if it is empty,
but if it's not empty, the "rd" will fail anyway, so no harm done. my logic might be horse-dukey, so if you manage
to translate it into working code, be careful about testing.
ps: my mistake, forgot to put the path-strings
in the code. (p1, pn)

Report •
Related Solutions

Ask Question