@@ -254,19 +254,22 @@ dir4 <- function(path = getwd(),
254
254
if (is.na(path ))
255
255
return (message(' The path cannot be NA!' ))
256
256
if (dir.exists(path )) {
257
- # os <- Sys.info()['sysname']
258
- # # windows ----
259
- # if(os == 'Windows') {
260
- # non_ascii <- readLines(system.file('resource/non-ascii-windows.txt', package = 'mindr'), encoding = 'UTF-8')
261
- # tree <- paste0('tree "', path, '"', ifelse(dir_files, ' /F', ''))
262
- # mytree <- system(tree, intern = T)
263
- # md <- mytree[-(1:3)]
264
- # ## dir_files
265
- # if(dir_files){
266
- # loc_files <- !(grepl(non_ascii[1], md) | grepl(non_ascii[3], md))
267
- # md[loc_files] <- unlist(sapply(md[loc_files], function(x) count_space(x, sep = non_ascii[2])))
268
- # }
269
- # } else {
257
+ os <- Sys.info()[' sysname' ]
258
+ # windows ----
259
+ if (os == ' Windows' ) {
260
+ oldlocale <- Sys.getlocale(' LC_CTYPE' )
261
+ on.exit(Sys.setlocale(' LC_CTYPE' , oldlocale ))
262
+ Sys.setlocale(' LC_CTYPE' , ' Chinese' )
263
+ non_ascii <- readLines(system.file(' resource/non-ascii-windows.txt' , package = ' mindr' ), encoding = ' UTF-8' )
264
+ tree <- paste0(' tree "' , path , ' "' , ifelse(dir_files , ' /F' , ' ' ))
265
+ mytree <- system(tree , intern = T , show.output.on.console = TRUE )
266
+ md <- mytree [- (1 : 3 )]
267
+ # # dir_files
268
+ if (dir_files ){
269
+ loc_files <- ! (grepl(non_ascii [1 ], md ) | grepl(non_ascii [3 ], md ))
270
+ md [loc_files ] <- unlist(sapply(md [loc_files ], function (x ) count_space(x , sep = non_ascii [2 ])))
271
+ }
272
+ } else {
270
273
# # non windows ----
271
274
# data.tree method ----
272
275
non_ascii <- readLines(system.file(' resource/non-ascii-datatree.txt' , package = ' mindr' ), encoding = ' UTF-8' )
@@ -279,7 +282,7 @@ dir4 <- function(path = getwd(),
279
282
mytree <- data.tree :: as.Node(data.frame (pathString = mydir ))
280
283
md <- print(mytree )[, 1 ]
281
284
md [1 ] <- rootname
282
- # }
285
+ }
283
286
284
287
# Both ----
285
288
if (' txt' %in% output ) {
0 commit comments