feature: added FS utils
This commit is contained in:
		
							parent
							
								
									e89429a93c
								
							
						
					
					
						commit
						72cc77ef77
					
				
							
								
								
									
										15
									
								
								pkg/io/files/file_open_helper.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								pkg/io/files/file_open_helper.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
package files
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func OpenFileForWriting(fileLocation string) (*os.File, error) {
 | 
			
		||||
	err := MkdirParent(fileLocation)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return os.Create(fileLocation)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								pkg/io/files/parent_file_creator.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								pkg/io/files/parent_file_creator.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
package files
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func MkdirParent(fileLocation string) error {
 | 
			
		||||
	fileLocation = strings.ReplaceAll(fileLocation, "\\", "/")
 | 
			
		||||
	indexOfSlash := strings.LastIndex(fileLocation, "/")
 | 
			
		||||
	if indexOfSlash > 0 {
 | 
			
		||||
		parentDirLocation := fileLocation[:indexOfSlash]
 | 
			
		||||
		parentDirCreationErr := os.MkdirAll(parentDirLocation, os.ModeDir)
 | 
			
		||||
 | 
			
		||||
		if parentDirCreationErr != nil {
 | 
			
		||||
			return parentDirCreationErr
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user