Changed filepath script to output to csv instead of txt

This commit is contained in:
2015-08-04 10:10:58 -04:00
parent f18fc308f9
commit 192ce76dc5
6 changed files with 46 additions and 7 deletions

View File

@@ -41,4 +41,4 @@ Hopefully, having the txt produced by this program will help you easily restore
**Script 2 SMB/NTFS Path Length** **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. 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.

View File

@@ -1,15 +1,29 @@
@echo off @echo off
echo This script will scan all local drives for any paths bigger than 255 characters. 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 .
echo . echo .
pause pause
cls cls
call ruby\bin\irb.bat source\filepath.rb call ruby\bin\irb.bat source\filepath.rb
xcopy "files.txt" "%userprofile%\Desktop"
xcopy "files.csv" "%userprofile%\Desktop"
cls cls
echo The script has finished.... echo The script has finished....
echo You can find files.txt on your desktop.
echo You can find files.csv on your desktop.
echo . echo .
pause pause
exit exit

12
source/csvFile.rb Normal file
View File

@@ -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

View File

@@ -1,4 +1,5 @@
require 'FileUtils' require 'FileUtils'
require_relative 'csvFile'
class Filecreate class Filecreate
@@ -18,4 +19,8 @@ class Filecreate
self.open.puts(whatToWrite) self.open.puts(whatToWrite)
self.open.close self.open.close
end end
def writeToCsv(whatToWrite)
Csvfile.new.writeToCsv(self.filename,whatToWrite)
end
end end

View File

@@ -3,7 +3,7 @@ require_relative 'filesUtil'
require_relative 'filecreate' require_relative 'filecreate'
@outputFile = Filecreate.new @outputFile = Filecreate.new
@outputFile.filename = "files.txt" @outputFile.filename = "files.csv"
@outputFile.create @outputFile.create
@filesUtil = Filesutil.new @filesUtil = Filesutil.new
@fileSystem = Windowsfilesystem.new @fileSystem = Windowsfilesystem.new
@@ -15,8 +15,12 @@ require_relative 'filecreate'
@files = @filesUtil.findFilesByFileName(drive.Path,'*.*') @files = @filesUtil.findFilesByFileName(drive.Path,'*.*')
@filesTooLong = @files.select{|f| @filesUtil.getExpandedPathByFileName(f).length > 255} @filesTooLong = @files.select{|f| @filesUtil.getExpandedPathByFileName(f).length > 255}
@filesTooLong.each do |file| @filesTooLong.each do |file|
@whatToWrite = @filesUtil.getExpandedPathByFileName(file) @pathLength = @filesUtil.getExpandedPathByFileName(file).length.to_s
@outputFile.writeWindowsFilePath(@whatToWrite) @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 end
end end

View File

@@ -22,4 +22,8 @@ class Filesutil
return Dir["#{path}/*.*"] return Dir["#{path}/*.*"]
end end
def getFileBasename(file)
return File.basename(file.to_s)
end
end end