Use one button to go to a folder, and also delete all *.log?
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 2
- Joined: 2015-08-01, 17:05 UTC
Use one button to go to a folder, and also delete all *.log?
Is it possible to use one button to go to a folder, and also delete all *.log file?
I have a button in the tool bar, the command is "cd c:\temp". When I click the button, the totalcmd would go to the directory c:\temp.
But I also want to delete all *.log file when I click the button. Is it possible?
Thank.
Jim
I have a button in the tool bar, the command is "cd c:\temp". When I click the button, the totalcmd would go to the directory c:\temp.
But I also want to delete all *.log file when I click the button. Is it possible?
Thank.
Jim
Hello, Jim.
I guess the following commandline should work
Cheers,
Karl
I guess the following commandline should work
Code: Select all
cmd.exe /c "cd /d C:\temp & del *.log"
Karl
But it would be safer to do
instead, just for case when cd fails and del then deletes files from another directory.
Code: Select all
cmd.exe /c "del C:\temp\*.log"
You heard of errorlevel?MVV wrote:But it would be safer to doinstead, just for case when cd fails and del then deletes files from another directory.Code: Select all
cmd.exe /c "del C:\temp\*.log"
Code: Select all
cmd.exe /c "cd /d C:\temp & IF NOT ERRORLEVEL 1 (del *.log)"
Last edited by milo1012 on 2015-08-03, 02:05 UTC, edited 1 time in total.
TC plugins: PCREsearch and RegXtract
milo1012,
Why are you doing 2 operations and check for error if one does completely the same thing?
BTW your command may be written in a shorter way:
Here && executes second command only if first one succeeded. Also || exists that does the opposite.
Anyway, my command is simpler and does what was asked.
Why are you doing 2 operations and check for error if one does completely the same thing?
BTW your command may be written in a shorter way:
Code: Select all
cd /d C:\temp && del *.log
Anyway, my command is simpler and does what was asked.
Because that very syntax may be also used in a standalone batch file, and not just squeezed as a parameter to cmd.exe,MVV wrote:Why are you doing 2 operations and check for error if one does completely the same thing?
...
Here && executes second command only if first one succeeded
in case you want to swap the CD command with something else and need a check for errorlevel then.
TC plugins: PCREsearch and RegXtract
And that is related to my previous answer, because...?MVV wrote:You can use && and || in batch file too. cmd.exe /c processes simply a single batch line, with same rules applied.
I just said that you can simply copy and paste common commands schemes that way, so that you may not have to have to think through every altered command.
BTW, with the errorcheck you can keep the batch open and output some message in case of errors.
By whose standard? There is no correct or wrong when it comes to multiple solutions for problems like the OP.MVV wrote:Anyway, it is a bad style to mix multiple commands in a line
And other built-in things like mkdir and copy don't effect the next lines?MVV wrote:...especially such as cd which affects next lines too.
Most things in a batch may be effected by previous lines. We really shouldn't discuss platitudes here.
All solutions work.
TC plugins: PCREsearch and RegXtract