BleepingComputer.com: Batch Program Help

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch Program Help Multiple Commands in Batch

#1 User is offline   pntblltrc4 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 13
  • Joined: 04-October 08
  • Gender:Male

Posted 30 November 2010 - 10:12 PM

Ok here is the question. I need to build a batch file that will search the c: drive for a given file, if that file exists I need it to delete it. Is it possible to do this with batch, or am I hitting its limitation? If its possible could someone please give me and example how the string should look.

Thank You For Your Help Everyone

Aaron
Isaiah 54:17
No weapon that is formed against thee shall prosper; and every tongue [that] shall rise against thee in judgment thou shalt condemn. This [is] the heritage of the servants of the LORD, and their righteousness [is] of me, saith the LORD.

#2 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 30 November 2010 - 11:11 PM

You want to make a batch file but did you try the DEL command ?

DEL /S can delete matching files from all sub-folders. Use very carefully. Type DEL /? to see all options.

#3 User is offline   pntblltrc4 

  • New Member
  • Pip
  • Find Topics
  • Group: Members
  • Posts: 13
  • Joined: 04-October 08
  • Gender:Male

Posted 30 November 2010 - 11:27 PM

YOU ARE MY HERO!!!!!!!!!!!! By chance you would know how to take all the results of my .bat file and export them into a single log.txt?
Isaiah 54:17
No weapon that is formed against thee shall prosper; and every tongue [that] shall rise against thee in judgment thou shalt condemn. This [is] the heritage of the servants of the LORD, and their righteousness [is] of me, saith the LORD.

#4 User is offline   Romeo29 

  • Learning To Bleep
  • PipPipPipPipPipPip
  • Find Topics
  • Group: BC Advisor
  • Posts: 2,834
  • Joined: 06-July 08
  • Gender:Not Telling
  • Location:127.0.0.1

Posted 01 December 2010 - 12:49 AM

In your batch file
Put > followed by logfile pathname to write output of command to new log file.
Put >> in the same way to append to an already existing log file.

For example,

DIR C: > c:\mylogfile.txt
DIR C:\Windows >> c:\mylogfile.txt


Do this wherever needed. You can do fancy stuff too, like putting in date and time at the beginning of log :

SET LogFile=C:\mylogfile.txt
ECHO. >> %LogFile%
ECHO %Date% >> %LogFile%
ECHO %Time% >> %LogFile%
ECHO. >> %LogFile%


#5 User is offline   JosiahK 

  • Forum Regular
  • PipPipPip
  • Find Topics
  • Group: Members
  • Posts: 258
  • Joined: 05-August 10
  • Gender:Male

Posted 03 December 2010 - 09:10 AM

Be aware that the del command will remove all files by that name, and only works against that name. If there are other files with the same name they'll be deleted as well. If you want to delete every case of a specific file (name and contents are both the same) you could get a bit of a safeguard by checking that the file size or date are the same.
Quod non mortiferum, fortiorem me facit.
I don't read minds. Please help everyone by answering any questions and reporting on the results of any instructions. Query any concerns and explain problems or complications.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users