Computing.Net > Forums > Programming > Bat File Help

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.

Bat File Help

Reply to Message Icon

Name: WolvenArrow
Date: April 27, 2009 at 01:36:02 Pacific
OS: Microsoft Windows Vista Business
CPU/Ram: 2.2 GHz / 3582 MB
Product: Asus / P5KPL-CM
Subcategory: Batch
Comment:

I am trying to make a batch file that searches for a certain file or files, eg. "song.mp3" on the hard drive, and if the file(s) exist on the hard drive it deletes the directory the file(s) are in. eg.

I run the .bat file from my usb F:\
searches for the file from the usb (F:\)
finds the file or files here:
C:\Users\Richard\Music\song.mp3
Then the bat file deletes all the files that are in that directory only.



Sponsored Link
Ads by Google

Response Number 1
Name: WolvenArrow
Date: April 27, 2009 at 23:32:57 Pacific
Reply:

FOR /F "tokens=*" %%G IN ('DIR /B /s *song*') DO rmdir /s

Something like that


0

Response Number 2
Name: Judago
Date: April 28, 2009 at 00:19:05 Pacific
Reply:

I think you have pretty much got it all you need is to add %%~dpG to the end of it and specify a hard drive in the dir command.


0

Response Number 3
Name: WolvenArrow
Date: April 28, 2009 at 00:45:24 Pacific
Reply:

http://img145.imageshack.us/img145/...

still doesn't seem to work

C:\Documents and Settings\Richard\Desktop\New Folder
is the location of the song.mp3
....


0

Response Number 4
Name: Judago
Date: April 28, 2009 at 01:15:19 Pacific
Reply:

Add the /q switch to the rmdir to forgo confirmation "rmdir /s /q %%~dpG" it would also be an idea to add double quotes around "%%~dpG" to avoid any possible conflicts with spaces and ampersands.

rmdir /s /q "%%~dpG"


0

Response Number 5
Name: WolvenArrow
Date: April 28, 2009 at 01:40:38 Pacific
Reply:

Awesome, thanks for your help


0

Related Posts

See More



Response Number 6
Name: Judago
Date: April 28, 2009 at 02:04:55 Pacific
Reply:

No problems...

One thought has come to mind though, what if song.mp3 happens to be on the desktop? I imagine that windows won't allow it to be removed, nor should it and if it does I'm unsure of the consequences.


0

Response Number 7
Name: WolvenArrow
Date: April 28, 2009 at 02:12:11 Pacific
Reply:

hmmm, yeah well i better make sure that the certain file i might want to move isn't in a critical place like the program files folder or on the desktop ;)


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: Bat File Help

Bat File Help www.computing.net/answers/programming/bat-file-help-/9414.html

Bat file help www.computing.net/answers/programming/bat-file-help-/10866.html

Bat + reg = 1 bat file help!!! www.computing.net/answers/programming/bat-reg-1-bat-file-help/9468.html