Articles

delete files in a folder (batch)

July 24, 2006 at 06:56:15
Specs: windows xp, intel/512

hi
C:\Documents and Settings\user\Desktop\clients\x\t
is the folder tree i am working on.
the batch file is placed on the desktop.
i have the following code to delete all *.jpeg files from the folder "t"

@echo off
dir /s/b/ad "C:\Documents and Settings\user\Desktop\clients"
find /v /i "C:\Documents and Settings\Documents and Settings\user\Desktop\clients"

for %f in (*.*) do @del /s %%f

::done
pause


if u look above after clients as per the structure it would show a folder "x" and then the folder "t" . both these folders are displayed on the screen when i run the above batch file.BUT it does not delete the *.jpeg inside the "t" folder. also i dont want to delete any *.jpeg in any other folder ie client,x.
kindly help .
is there some problem with my for command?

very urgent.please help
cheers!!!


See More: delete files in a folder (batch)

Report •


#1
July 24, 2006 at 08:32:40


@echo off
cd..
dir /s/b/ad "C:\Documents and Settings\user\Desktop\clients"
find "*.xml" "C:\Documents and Settings\Documents and Settings\user\Desktop\clients" <t

if exist *.jpeg echo y | del /s *.jpeg
:: DONE
pause


i modified the code to above..but when i run it it gives the error:
cannot find the file !!
why is is not able to find the jpeg's?
kindly help


Report •

#2
July 24, 2006 at 08:41:13


@echo off
dir /s /b "C:\Documents and Settings\user\Desktop\clients\x\*.jpeg" > Files.txt
for /f %%a in (Files.txt) do del %%a


Report •

#3
July 24, 2006 at 23:33:08

Call me simple minded.


del /s "C:\Documents and Settings\user\Desktop\clients\x\t\*.jpeg"


If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
July 25, 2006 at 01:09:38

@dtech and mechanix2go

@echo off
dir /s /b "C:\Documents and Settings\user\Desktop\clients\x\*.jpeg" > Files.txt
for /f %%a in (Files.txt) do del %%a

this is a simple solution BUT THE x folder changes everytime ..ie the name of this folder changes .
hence i wrote the above code, my second post so that the program automatically tracks the contstant "t" folder and deletes the *.jpeg files of it.
i repeat all the jpeg files of t folder should only be deleted.
the name of "x" folder varies and only the path uptil clients remains the same. ofcourse the "t" folder also remains the same.
kindly help now
cheers


Report •

#5
July 25, 2006 at 04:41:29

@echo off

dir/s/b/ad "c:\Documents and Settings\user\Desktop\clients\" |find /i "\t" > #
for /f "tokens=*" %%D in (#) do echo del "%%D\*.jpeg"

===
That's 3 lines beginning with:

@echo
dir
for



If at first you don't succeed, you're about average.

M2


Report •

#6
July 25, 2006 at 05:18:08

@Mechanix2go

sorry friend that doesnt work.
the .jpeg files in "t" are not deleted. the dos screen flashes when i run the file, but nothing happens.
kindly help
cheers


Report •

#7
July 25, 2006 at 05:24:56

the error message is:
the system did not find the file specified.
although i have checked all the folders and files are intact.
kindly help

Report •

#8
July 25, 2006 at 05:44:31


@echo off
setlocal

set FolderPathBase=C:\Documents and Settings\user\Desktop\clients\*.*

for /f "tokens=*" %%i in ('dir /b /ad "%FolderPathBase%"') do (cd /d "%FolderPathBase%\%%i\" && del . /s /q >nul 2>&1)
endlocal


ok now the above code is working for deleting the fileS BUT it is also deleting the .jpegs inside "x" whereas only those inside "transmittal" should be deleted.
kindly help
very near..yet so far
cheers


Report •

#9
July 25, 2006 at 06:32:04

If you look at this lline:

for /f "tokens=*" %%D in (#) do echo del "%%D\*.jpeg"

from #5 you may notice that because of the "echo" it doesn't *DO* any deletion, but simply verifies that it's on tyhe right track. I did this to keep from creating a loose cannon.

Edit out the "echo" from that line and I think it will work.

BTW doing a global delete after a CD is a BAD idea. If the CD fails, you've got trouble.


If at first you don't succeed, you're about average.

M2


Report •

#10
July 26, 2006 at 08:12:11


@echo off

setlocal

set FolderPathBase=C:\Documents and Settings\user\Desktop\c\*.*

for /f "tokens=*" %%i in ('dir /b /ad "%FolderPathBase%"') do (cd /d "%FolderPathBase%\%%i\transmittals\ " && copy C:\Documents and Settings\user\Desktop\c\x\t\2.xml C:\y >nul 2>&1)

endlocal

pause


why doesnt the copy command work?
if i replace copy by del *.jpeg /s it works fine and does what is desired. but NOW I WANT TO JUST MOVE THE FILE FROM THE FOLDER TO ANOTHER FOLDER. BUT IT GIVES ERROR--path not found.

why??
kindly help

cheers


Report •

#11
July 26, 2006 at 15:27:58

Hi
Hi
Maybe I'm on the wrong track here, but will this work.
delete the /p which asks for confirmation.
delete it if works ok.

@echo off
dir /b /s /ad| find /i "Documents and Settings\user\Desktop\clients\" | find /i "\x\t" >

Dirs.txt
for /f "tokens=*" %%a in (Dirs.txt) do if exist "%%a"\*.jpeg del "%%a"\*.jpeg /p



Report •

#12
July 27, 2006 at 00:18:59

i said i want to MOVE the file to a diff folder using the move comamnd. but it aint works. del is working fine as in my earlier posts.
kindly help cheers

Report •


Ask Question