Search found 483 matches

by Compo
01 Jul 2020 09:51
Forum: DOS Batch Forum
Topic: Best command to delete a file?
Replies: 3
Views: 122

Re: Best command to delete a file?

It's a matter of opinion really. I believe that you should be polite, i.e ask for an action only if its needed, so my preference is to see if the file exists prior to asking for it to be deleted. However checking if the file exists, is an action in itself, so some would see it as no less efficient t...
by Compo
24 May 2020 14:42
Forum: DOS Batch Forum
Topic: Just the total size of a folder & subfolders
Replies: 3
Views: 543

Re: Just the total size of a folder & subfolders

The following alternative, will work with your output: @SetLocal EnableExtensions @For /F Tokens^=3 %%G In ('Dir /S/A-D/-C 2^>NUL')Do @Set /A $=#,#=%%G 2>NUL @Echo %$% bytes @Pause I'm not sure if all system languages output the filesize as the third token, so if this is going to be used for any oth...
by Compo
20 Apr 2020 13:19
Forum: DOS Batch Forum
Topic: How to disable Avast until reboot
Replies: 7
Views: 1696

Re: How to disable Avast until reboot

I suppose that this is technically an answer to your question.

How bad would an anti-malware product be if a script was able to turn it off, (until it had completed tasks unhindered by that anti-malware product)?
by Compo
20 Apr 2020 05:41
Forum: DOS Batch Forum
Topic: how to stop a space from aborting a batch process
Replies: 4
Views: 1510

Re: how to stop a space from aborting a batch process

Based upon your provided example, I do not see any need for the start command in this case: Del /F /A "%ProgramFiles%\glarysoft\malware hunter\mhtray.exe" The del command is internal, so effectively you're opening a new cmd.exe window with the /K option, which would then require closing afterwards, ...
by Compo
11 Oct 2019 14:44
Forum: DOS Batch Forum
Topic: date not showing
Replies: 3
Views: 7197

Re: date not showing

The returned date from date /t is not consistent across PC's or users. I'm assuming that you were previously seeing ddd and trying to ignore it by selecting the second token. You can still use the same method, if you like, by just checking for an empty value for the second token: For /F "Tokens=1*" ...
by Compo
10 Apr 2019 05:52
Forum: DOS Batch Forum
Topic: set %RANDOM% for timeout command
Replies: 7
Views: 2900

Re: set %RANDOM% for timeout command

You're setting the variable %watch% , whilst in a parenthesised block of code. In order to use the new value, you need to delay the expansion of the variable at run time, as opposed to read time. @Echo Off Title BulBot Color 70 :MasterLabel Set /P "input=" If /I "%input%"=="clear" ClS If /I "%input%...
by Compo
10 Mar 2019 20:03
Forum: DOS Batch Forum
Topic: Reconcile files to be deleted with list?
Replies: 7
Views: 2248

Re: Reconcile files to be deleted with list?

Similarly, but using /X instead of /B and/or /E, as long as your filenames do not themselves contain any space, (or poison) characters:

Code: Select all

FindStr /ILVX "%Exceptions: =.log %.log"
Or alternatively…

Code: Select all

FindStr /XVIC:"%Exceptions: =.log" /C"%.log"
by Compo
12 Aug 2018 08:48
Forum: DOS Batch Forum
Topic: Filtering registry UninstallString dependant on drive
Replies: 1
Views: 1080

Re: Filtering registry UninstallString dependant on drive

Here's an untested example script which may output the required uninstall key. It is based off the information you've provided, except for one assumption, that being the string "Java" will be contained within the same REG_SZ string as "D:\" @Echo Off SetLocal EnableExtensions DisableDelayedExpansion...
by Compo
11 Aug 2018 03:52
Forum: DOS Batch Forum
Topic: Retrieve/Iterate all .doc files in a directory
Replies: 5
Views: 2185

Re: Retrieve/Iterate all .doc files in a directory

What version of Windows are you using? I can't replicate your results on Windows 7. I have confirmed the behavior on several different OS's over the years, and agree with sst , that you must have modified settings on your Windows 7 system. My settings are the defaults, 0 for the volume state, and 2...
by Compo
09 Aug 2018 04:42
Forum: DOS Batch Forum
Topic: Retrieve/Iterate all .doc files in a directory
Replies: 5
Views: 2185

Retrieve/Iterate all .doc files in a directory

What is the recommended method to get only the files in a directory with the extension .doc ? I often see, and use , examples of For loops like this: For %A In (*.doc) Do @Echo %A or this: For /F "Delims=" %A In ('Dir /B/A-D *.doc') Do @Echo %A However in the real world that does not do what is aske...
by Compo
21 Jul 2018 13:45
Forum: DOS Batch Forum
Topic: Context Menu options using CMD.exe or Powershell
Replies: 7
Views: 2822

Re: Context Menu options using CMD.exe or Powershell

sst, the point of my very simplified answer to the SO question was the use of %W and I'm also aware that it included a possibly unwanted new line, although it wasn't stated, (only the doublequotes) , which mine didn't have, or a possibly unwanted trailing backslash . BTW, the powershell example I pr...
by Compo
21 Jul 2018 10:48
Forum: DOS Batch Forum
Topic: Context Menu options using CMD.exe or Powershell
Replies: 7
Views: 2822

Re: Context Menu options using CMD.exe

As an opening comment, I think that the SO answer from sst was overly complex for the task , given that %W does what was needed, (the other two answers show it in use)! Here's something from an answer I used here , which creates a context menu entry for making a new directory with today's date: @Pow...
by Compo
19 Jul 2018 03:45
Forum: DOS Batch Forum
Topic: List of files on HDD
Replies: 7
Views: 2684

Re: List of files on HDD

You could use the Dir command as provided by penpen: (For /F "Delims=" %A In ('Dir /B/S/A-D *.jpg *.mov *.mp4') Do @Echo %~nxA)>"j.txt" You could also use the RoboCopy command: (For /F "Delims=" %A In ('RoboCopy . null *.jpg *.mov *.mp4 /S /XJ /L /NS /NC /NDL /NJH /NJS') Do @Echo %~nxA)>"j.txt" Or m...
by Compo
15 Jul 2018 12:29
Forum: DOS Batch Forum
Topic: List of files on HDD
Replies: 7
Views: 2684

Re: List of files on HDD

Using ForFiles, whilst not the most efficient command, is a simple command to use, (Enter ForFiles /? at the Command Prompt for usage information).

Code: Select all

ForFiles /S /C "Cmd /C If @IsDir==FALSE Echo @File">"j.txt"
by Compo
30 Jun 2018 13:06
Forum: DOS Batch Forum
Topic: Need help with batch file
Replies: 3
Views: 1440

Re: Need help with batch file

If it works then it cannot really be made more efficient, other than not setting variables unnecessarily . I suppose it may look tidier to some, by breaking those long lines down into smaller portions , and could possibly be made a little more robust: @Echo Off CD /D "%~dp1" 2>Nul || Exit /B Set "cd...