0

I'm trying to write a script that will run through a directory tree and generate a checksum for the contents of each folder and write the checksum to that folder; I've managed to do everything with the following code except write the checksum to the folder, it's currently writing everything to the root directory.

FOR /R "C:\_input\test" /D %%a IN (*) DO md5deep64 -r "%%a" >> "%%a.md5"

I thought I might be able to do something with the various modifiers (%~I) but no joy. Any ideas?

Tom
  • 29
  • 1
  • 8
  • Perhaps, `>"%%a\%%~nxa.md5"` is what you wanted; _although writing to a file inside a directory that your running the checksum against will probably be a problem. You may wish to write it to the current directory, `>"%%~nxa.md5"`, then move it, `Move /Y "%%~nxa.md5" "%%a"`._ – Compo Jun 30 '18 at 17:35
  • Since the `for /r /d` iterates all subfolders, the `-r` to md5deep is redundant, should IMO be `FOR /R "C:\_input\test" /D %%a IN (*) DO md5deep64 "%%a\*" > "%%a.md5"` –  Jun 30 '18 at 18:08
  • @LotPings yes running '-r' twice feels unnecessary but I can't seem to get md5deep to create the hash without it. Thanks. – Tom Jun 30 '18 at 22:58

1 Answers1

1

Based on your latest comment and my own, I think this may be what you want:

As a batch file:

@For /D %%A In ("C:\_input\test\*) Do @md5deep64 -r "%%A">"%%A.md5" & @Move /Y "%%A.md5" "%%A"

At the command line:

For /D %A In ("C:\_input\test\*) Do @md5deep64 -r "%A">"%A.md5" & @Move /Y "%A.md5" "%A"

Note that md5deep64.exe would need to be in the current directory or %Path%, otherwise you'd need to provide the full or relative path to it.

Compo
  • 36,585
  • 5
  • 27
  • 39