Batchscript todelete from 2fold basedon1folde

Microsoft Windows xp professional sp2 w/...
January 14, 2010 at 23:01:29
Specs: Windows Server 2003
Hi ,

I have 2 folders Folder X and Folder Y.I need to write a batch script which will take Folder X files as input and delete those files in Folder Y.

FOlder X -- 1.txt,2.xls,3.doc,4(no extension)

the files in folder X(1.txt,2.xls,3.doc,4(no extension)) should be deleted in FOLDERY.

Please tell me how I do the delete via Batch script.

Regards,
Mora


See More: Batchscript todelete from 2fold basedon1folde

Report •

#1
January 14, 2010 at 23:41:15
NOT tested

=============================
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d folderx') do (
if exist "foldery\%%a" del "foldery\%%a"
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 16, 2010 at 04:03:52
C:\Temp>dir /s /b
C:\Temp\1
C:\Temp\2
C:\Temp\1\1
C:\Temp\1\3
C:\Temp\1\4
C:\Temp\2\1
C:\Temp\2\4
C:\Temp\2\7
C:\Temp\2\8

C:\Temp>for %f in (C:\temp\1\*.*) do del c:\temp\2\%~nf

C:\Temp>del c:\temp\2\1

C:\Temp>del c:\temp\2\3
Could Not Find c:\temp\2\3

C:\Temp>del c:\temp\2\4

C:\Temp>

It's dirty, but it does as asked. Replace % with %% if you put it into a script.


Report •
Related Solutions


Ask Question