Changed filepath script to output to csv instead of txt
This commit is contained in:
@@ -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.
|
||||
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.
|
||||
@@ -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
|
||||
12
source/csvFile.rb
Normal file
12
source/csvFile.rb
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -22,4 +22,8 @@ class Filesutil
|
||||
return Dir["#{path}/*.*"]
|
||||
end
|
||||
|
||||
def getFileBasename(file)
|
||||
return File.basename(file.to_s)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user