Search found 478 matches

by Compo
10 Apr 2019 05:52
Forum: DOS Batch Forum
Topic: set %RANDOM% for timeout command
Replies: 7
Views: 571

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: 637

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: 493

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: 1115

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: 1115

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: 1503

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: 1503

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: 1519

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: 1519

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: 770

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...
by Compo
03 Jun 2018 06:03
Forum: DOS Batch Forum
Topic: Stop Command Prompt Empty Line
Replies: 17
Views: 2950

Re: Stop Command Prompt Empty Line

XY Problem How so? I'd define an XY problem as a communication problem in which the cause is masked because the person asking for help has presented incomplete information. There's absolutely no need to hide the actual name and/or version of the executable you are having difficulty with, it most ce...
by Compo
02 Jun 2018 06:01
Forum: DOS Batch Forum
Topic: How to create a subfolder based on current date?
Replies: 6
Views: 1220

Re: How to create a subfolder based on current date?

Here's a replication of my answer to you on StackOverflow . Because you're using RoboCopy for the copying process, here's a method which also uses it to determine the date: @Echo Off Set "sd=C:\EverNote" Set "dd=E:\EverNote" Set "ds=" If Not Exist "%sd%\" Exit /B For /F "Tokens=1-3Delims=/ " %%A In ...
by Compo
25 May 2018 06:35
Forum: DOS Batch Forum
Topic: Weird function issue - variables not staying set
Replies: 3
Views: 969

Re: Weird function issue - variables not staying set

SIMMS7400, why are you still using that particular :DOW call?, don't you consider my advice worthy of reading?

Please take a look at this response where I showed you a simpler way of getting those variables!
…and there was no need or requirement for delayed expansion.
by Compo
10 May 2018 20:57
Forum: DOS Batch Forum
Topic: try to add one string just after another string with comma
Replies: 6
Views: 1084

Re: try to add one string just after another string with comma

Based on the information you've provided, I think, (it's untested) , this may be nearer to what you need: @Echo Off Set "profname=MOCKUP_DL" Set "oprofname=QA_SL" If /I Not "%profname:~-2%%oprofname:~-2%"=="DLSL" ( If /I Not "%profname:~-2%%oprofname:~-2%"=="SLDL" GoTo :EOF) Set "gen_sch=T501-08815-...
by Compo
09 May 2018 07:01
Forum: DOS Batch Forum
Topic: try to add one string just after another string with comma
Replies: 6
Views: 1084

Re: try to add one string just after another string with comma

You didn't provide any information with your code above, is it working as you wished, or are there one or more issues with it?

Also, why are you thinking about the task in terms of search and replace? I see it as an insert task!