diff --git a/README.md b/README.md index b94914b..06139b3 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,4 @@ Hopefully, having the txt produced by this program will help you easily restore **Script 2 SMB/NTFS Path Length** -This program will create a txt with a list of files whose path exceeds 255 characters. The program scans local drives and should be run on the server not the client. \ No newline at end of file +This program will create a csv with a list of files whose path exceeds 255 characters. The program scans local drives and should be run on the server not the client. \ No newline at end of file diff --git a/network-path-length.bat b/network-path-length.bat index 02851ea..03495e2 100644 --- a/network-path-length.bat +++ b/network-path-length.bat @@ -1,15 +1,29 @@ @echo off + echo This script will scan all local drives for any paths bigger than 255 characters. -echo It will leave a .txt on your desktop. + +echo It will leave a .csv on your desktop. + echo . + echo . + pause + cls + call ruby\bin\irb.bat source\filepath.rb -xcopy "files.txt" "%userprofile%\Desktop" + +xcopy "files.csv" "%userprofile%\Desktop" + cls + echo The script has finished.... -echo You can find files.txt on your desktop. + +echo You can find files.csv on your desktop. + echo . + pause + exit \ No newline at end of file diff --git a/source/csvFile.rb b/source/csvFile.rb new file mode 100644 index 0000000..0c2f0cc --- /dev/null +++ b/source/csvFile.rb @@ -0,0 +1,12 @@ +require 'csv' + +class Csvfile + + def writeToCsv(filePath,whatToWrite) + CSV.open(filePath.to_s, "a") do |csv| + # csv << ["row", "of", "CSV", "data"] + csv << whatToWrite + end + end + +end \ No newline at end of file diff --git a/source/filecreate.rb b/source/filecreate.rb index 2586a67..e768e39 100644 --- a/source/filecreate.rb +++ b/source/filecreate.rb @@ -1,4 +1,5 @@ require 'FileUtils' +require_relative 'csvFile' class Filecreate @@ -18,4 +19,8 @@ class Filecreate self.open.puts(whatToWrite) self.open.close end + + def writeToCsv(whatToWrite) + Csvfile.new.writeToCsv(self.filename,whatToWrite) + end end \ No newline at end of file diff --git a/source/filepath.rb b/source/filepath.rb index 4433753..2d13ca0 100644 --- a/source/filepath.rb +++ b/source/filepath.rb @@ -3,7 +3,7 @@ require_relative 'filesUtil' require_relative 'filecreate' @outputFile = Filecreate.new -@outputFile.filename = "files.txt" +@outputFile.filename = "files.csv" @outputFile.create @filesUtil = Filesutil.new @fileSystem = Windowsfilesystem.new @@ -15,8 +15,12 @@ require_relative 'filecreate' @files = @filesUtil.findFilesByFileName(drive.Path,'*.*') @filesTooLong = @files.select{|f| @filesUtil.getExpandedPathByFileName(f).length > 255} @filesTooLong.each do |file| - @whatToWrite = @filesUtil.getExpandedPathByFileName(file) - @outputFile.writeWindowsFilePath(@whatToWrite) + @pathLength = @filesUtil.getExpandedPathByFileName(file).length.to_s + @path = @filesUtil.getExpandedPathByFileName(file).to_s + @path = @path.gsub("/","\\") + @fileName = @filesUtil.getFileBasename(file).to_s + @whatToWrite = [@pathLength,@path,@fileName] + @outputFile.writeToCsv(@whatToWrite) end end end \ No newline at end of file diff --git a/source/filesUtil.rb b/source/filesUtil.rb index 06bf623..92ee07f 100644 --- a/source/filesUtil.rb +++ b/source/filesUtil.rb @@ -22,4 +22,8 @@ class Filesutil return Dir["#{path}/*.*"] end + def getFileBasename(file) + return File.basename(file.to_s) + end + end \ No newline at end of file