Computing.Net > Forums > Programming > Compare too foldors

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Compare too foldors

Reply to Message Icon

Name: NuniM
Date: October 12, 2009 at 16:51:44 Pacific
OS: Windows XP
Subcategory: Batch
Tags: delet, code, foldor
Comment:

*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:
1.txt
2.txt
And in foldor B we got:
1.txt
2.txt
3.txt

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



Sponsored Link
Ads by Google

Response Number 1
Name: nbrane
Date: October 12, 2009 at 19:38:55 Pacific
Reply:

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
path1="c:\dir1\dir2"
'path2 is the one you want to "clean up"
path2="d:\dir1\dir2"
cd path2
call foo
exit
(that is:)
goto gtfo


foo:
for x in (dir /b /a:d) do
(
pn=p1
p1=path1+"\"+x
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.

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

:gtfo

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)


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Compare too foldors

Comparing Files+Folders using VBS www.computing.net/answers/programming/comparing-filesfolders-using-vbs/14112.html

Batch/script file - compare file na www.computing.net/answers/programming/batchscript-file-compare-file-na/18358.html

find 2txt files and compare with fc www.computing.net/answers/programming/find-2txt-files-and-compare-with-fc/18545.html