Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.2 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM spfileinfo.cmd - JeremyD
  4. @REM Recursively scan a directory gathering file information
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. use strict;
  13. use warnings;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts\\svcpack";
  17. use PbuildEnv;
  18. use ParseArgs;
  19. use Utils;
  20. use Digest;
  21. use IO::Dir;
  22. use IO::File;
  23. use File::Basename;
  24. use SP;
  25. sub Usage { print<<USAGE; exit(1) }
  26. <<Insert your usage message here>>
  27. USAGE
  28. parseargs('?' => \&Usage);
  29. for my $sku (SP::sp_skus()) {
  30. Utils::mkdir("$ENV{_NTPOSTBLD}\\SP\\data\\$sku");
  31. my $out_fh = IO::File->new("$ENV{_NTPOSTBLD}\\SP\\data\\$sku\\file_info.txt", 'w');
  32. walk_dir($out_fh, "$ENV{_NTPOSTBLD}\\$sku", "$ENV{_NTPOSTBLD}\\$sku");
  33. }
  34. sub walk_dir {
  35. my $out_fh = shift;
  36. my $root = shift;
  37. my $dir = shift;
  38. my $dh = IO::Dir->new($dir);
  39. if (defined $dh) {
  40. while (defined(my $file = $dh->read)) {
  41. next if $file =~ /^\.\.?$/;
  42. if (-d "$dir\\$file") {
  43. walk_dir($out_fh, $root, "$dir\\$file");
  44. }
  45. else {
  46. print $out_fh join ("\t", Utils::file_info("$dir\\$file", $root)), "\n";
  47. }
  48. }
  49. }
  50. }
  51. sub fileasdf_info {
  52. my $file = shift;
  53. my $root = shift;
  54. my $fh = IO::File->new("$file", 'r') or die "Unable to open file $file: $!";
  55. binmode($fh);
  56. my $filename;
  57. if ($file =~ /_$/) {
  58. $fh->seek(0x3c,0);
  59. for (;;) {
  60. my $c = $fh->getc;
  61. if (ord($c) == 0 or $fh->eof) { last }
  62. $filename .= "$c";
  63. }
  64. $fh->seek(0,0);
  65. }
  66. else {
  67. $filename = basename($file);
  68. }
  69. my ($size, $mtime) = ($fh->stat)[7,9];
  70. my $digest = Digest->new('SHA-1')->addfile($fh);
  71. (my $relative_name = $file) =~ s/^\Q$root\E\\//i;
  72. return ($relative_name, $filename, $size, $mtime, $digest->hexdigest);
  73. }