Search found 3577 matches

by aGerman
11 Oct 2019 00:27
Forum: DOS Batch Forum
Topic: Extract Part of a Filename
Replies: 11
Views: 242

Re: Extract Part of a Filename

OK now It makes more sense even if the delimiter in a csv file is usually not a tab. for /f "tokens=*" %%G in ('dir "%folder%\%mask%" /a:-d /b') do ( for /f "tokens=2 delims=." %%I in ("%%~nG") do ( for /f "tokens=*" %%H in ('type "%folder%\%%G"') do ( echo %%I %%H>> "%output%" ) ) ) Steffen
by aGerman
10 Oct 2019 17:04
Forum: DOS Batch Forum
Topic: Extract Part of a Filename
Replies: 11
Views: 242

Re: Extract Part of a Filename

It writes the date into the console window since you don't redirect it into the file. You have to know how it should look like in your file. I don't even understand what the
for /f "tokens=*" %%H in ('type "%folder%\%%G"') do ( ...
is for.

Steffen
by aGerman
10 Oct 2019 16:00
Forum: DOS Batch Forum
Topic: Extract Part of a Filename
Replies: 11
Views: 242

Re: Extract Part of a Filename

But that's not the code I offered to you. Have you been able to include it in your nested loop as I wrote? Maybe like that:

Code: Select all

for /f "tokens=*" %%G in ('dir "%folder%\%mask%" /a:-d /b') do (
  for /f "tokens=2 delims=." %%I in ("%%~nG") do echo %%I
)
Steffen
by aGerman
10 Oct 2019 12:50
Forum: DOS Batch Forum
Topic: Extract Part of a Filename
Replies: 11
Views: 242

Re: Extract Part of a Filename

Not sure what you tried because you didn't show the code.

Steffen
by aGerman
10 Oct 2019 12:25
Forum: DOS Batch Forum
Topic: certutil -hashfile of a directory
Replies: 5
Views: 211

Re: certutil -hashfile of a directory

The code was made for a Batch script. In a cmd window things work differently. Use %i rather than %%i and after DO use @certutil rather than certutil.

Steffen
by aGerman
10 Oct 2019 12:06
Forum: DOS Batch Forum
Topic: Extract Part of a Filename
Replies: 11
Views: 242

Re: Extract Part of a Filename

Not sure what to do with the date. Extracting it from the file name should be quite easy though. Say, the file name is in %%G in your nested loop ...
untested:

Code: Select all

for /f "tokens=2 delims=." %%I in ("%%~nG") do echo %%I
You should find the date in %%I, right?

Steffen
by aGerman
10 Oct 2019 10:12
Forum: DOS Batch Forum
Topic: certutil -hashfile of a directory
Replies: 5
Views: 211

Re: certutil -hashfile of a directory

I guess it should be either for %%i in ("C:\temp\mfiles\*.fdf") do certutil -hashfile "%%~i" SHA256| >"%%~dpni-hash256.txt" findstr /iv "hash certutil" or >"C:\temp\mfiles\filehash256.txt" (for %%i in ("C:\temp\mfiles\*.fdf") do certutil -hashfile "%%~i" SHA256|findstr /iv "certutil") depending on w...
by aGerman
08 Oct 2019 12:17
Forum: DOS Batch Forum
Topic: Really uexpected result of a script
Replies: 3
Views: 192

Re: Really uexpected result of a script

Where does %G come from? It should be either %G% (if you defined this variable somewhere else) or %%U if you meant the FOR variable.
Also remove the spaces around the == operator and consider to compare quoted strings at both sides of the ==.

Steffen
by aGerman
08 Oct 2019 11:15
Forum: DOS Batch Forum
Topic: Search through command line arguments.
Replies: 2
Views: 199

Re: Search through command line arguments.

This piece of code should meet your requirements: @echo off &setlocal if "%~1"=="" exit /b set /a "prt=0, other=0" >"attachments.txt" ( for %%i in (%*) do ( if /i "%%~xi"==".prt" ( set "CAD_FILE=%%~i" set /a "prt+=1" ) else ( set /a "other+=1" echo %%i ) ) ) if %prt% neq 1 ( del "attachments.txt" ec...
by aGerman
07 Oct 2019 13:43
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

That's weird. Right now I tried the code. Works nicely for me.

Steffen
by aGerman
07 Oct 2019 13:21
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

Actually Antonio's idea is pretty good. Sometimes I miss the obvious. Without having tested yet - the reason for the issue might be that your real file names contain spaces or other special characters. Try to update the loop like that for %%f in ("File1.exe" "File2.exe" "File3.exe") do ( if exist "%...
by aGerman
06 Oct 2019 12:01
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

I figured you would ask. Background: https://en.wikipedia.org/wiki/Bitwise_operation I'll refrain from explaining how AND and OR work. Use the Wikipedia link for reference. It's working on bit-level which means to understand what I'm doing here you have to understand that computers work with zeros a...
by aGerman
06 Oct 2019 09:42
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

You can use a bitset where you add powers of two for every found file. set "bitset=0" if exist "%userprofile%\Desktop\File1.exe" set /a "bitset |= 1" if exist "%userprofile%\Desktop\File2.exe" set /a "bitset |= 2" if exist "%userprofile%\Desktop\File3.exe" set /a "bitset |= 4" set /a "f1orf2=bitset ...
by aGerman
06 Oct 2019 08:58
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

Don't know if I understood your logic. But I guess it should be one out of these two if not exist "%userprofile%\Desktop\file3.exe" ( rem your message and exit ) else if not exist "%userprofile%\Desktop\file1.exe" if not exist "%userprofile%\Desktop\file2.exe" ( rem your message and exit ) rem conti...
by aGerman
06 Oct 2019 07:54
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 449

Re: If one of two files exist then do something.

Depends on the situation. In your case the second should be okay.

Steffen