Computing.Net > Forums > Programming > delete files in a folder (batch)

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.

delete files in a folder (batch)

Reply to Message Icon

Name: indiewolf
Date: July 24, 2006 at 06:56:15 Pacific
OS: windows xp
CPU/Ram: intel/512
Product: hp
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: indiewolf
Date: July 24, 2006 at 08:32:40 Pacific
Reply:


@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


0

Response Number 2
Name: dtech10
Date: July 24, 2006 at 08:41:13 Pacific
Reply:


@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


0

Response Number 3
Name: Mechanix2Go
Date: July 24, 2006 at 23:33:08 Pacific
Reply:

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


0

Response Number 4
Name: indiewolf
Date: July 25, 2006 at 01:09:38 Pacific
Reply:

@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


0

Response Number 5
Name: Mechanix2Go
Date: July 25, 2006 at 04:41:29 Pacific
Reply:

@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


0

Related Posts

See More



Response Number 6
Name: indiewolf
Date: July 25, 2006 at 05:18:08 Pacific
Reply:

@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


0

Response Number 7
Name: indiewolf
Date: July 25, 2006 at 05:24:56 Pacific
Reply:

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


0

Response Number 8
Name: indiewolf
Date: July 25, 2006 at 05:44:31 Pacific
Reply:


@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


0

Response Number 9
Name: Mechanix2Go
Date: July 25, 2006 at 06:32:04 Pacific
Reply:

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


0

Response Number 10
Name: indiewolf
Date: July 26, 2006 at 08:12:11 Pacific
Reply:


@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


0

Response Number 11
Name: dtech10
Date: July 26, 2006 at 15:27:58 Pacific
Reply:

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



0

Response Number 12
Name: indiewolf
Date: July 27, 2006 at 00:18:59 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: delete files in a folder (batch)

zip all the .csv files in a folder www.computing.net/answers/programming/zip-all-the-csv-files-in-a-folder/16724.html

Batch to Delete files in a folder www.computing.net/answers/programming/batch-to-delete-files-in-a-folder/16299.html

Batch Rename files in a folder www.computing.net/answers/programming/batch-rename-files-in-a-folder/15096.html