Non classé ((EXCLUSIVE)) Ruby GolF :: Flatten A Directory Tree Par loopodisfness Publié le 26 février 2021 0 0 16 Partager sur Facebook Partager sur Twitter Partager sur Google+ Partager sur Reddit Partager sur Pinterest Partager sur Linkedin Partager sur Tumblr Ruby GolF :: Flatten A Directory Tree ⚹ DOWNLOAD directory?(item) # subdirectory flatten(item, dest_dir) # recursively flatten subdir else #file rename_file(item, dest_dir, 0) # attempt to rename the file end end # check if the directory is empty, if so delete it # special case, ruby won’t consider a dir empty if it contains. ‘, ‘ ‘, ‘ DS_Store’]# max file rename attempts$max_attempts = 20# initial directory tree depth$depth = 0# max allowed directory tree depth$max_depth = 10def flatten(source_dir, dest_dir) # increment the tree depth $depth += 1 # if surpassed max allowed tree depth, exit the directory if $depth > $max_depth puts « \n\n– Max folder depth reached in ‘#{source_dir}’ –\n\n » $depth -= 1 # exit this directory return end # ensure dir paths end with ‘/’ source_dir += « / » if source_dir[-1] != « / » dest_dir += « / » if dest_dir[-1] != « / » # read the items of the directory puts « Flattening contents of ‘#{source_dir}’ to ‘#{dest_dir}’\n » Dir.. entries(source_dir) – $excludes) empty? and $depth > 1 puts « deleting #{source_dir} » if File.. DS_Store # delete DS_Store first if dir otherwise empty # also don’t delete the directory if it’s the root directory begin if (Dir. Allway Sync Pro 15 Activation Key rename(filename, new_path) endend# START # source dir is first argument, otherwise current directorysource_dir = ARGV.. entries(source_dir) each do |item| next if $excludes include?(item) # skip excludes item = source_dir + item # realize full path if File.. basename(filename) # set what the new full path ought to be new_path = dest_dir + fname # if we are attempting new versions append the version to the basename before the extension if version > 0 new_path = dest_dir + File.. file?(« #{source_dir} DS_Store ») _ = `rm « #{source_dir} DS_Store »` end Dir delete(source_dir) end rescue # do nothing end $depth -= 1 # exit this directoryend# renames the file, moving it to the dest_dir if the file# isn’t already in the directory at dest_dirdef rename_file(filename, dest_dir, version) # file already in dest_dir? if File.. basename(filename, » * ») + « _ » + version to_s + File extname(filename) end # if the new path already exists, try again if File. كيف تنسخ على سي دي Dvd Free Download Itr Forms Excel Format Free Primer Design Software Mac file?( new_path ) puts(« File ‘#{new_path}’ exists « ) if (version > $max_attempts) puts « Max rename attempts reached for ‘#{filename}’ » end rename_file(filename, dest_dir, version += 1) else puts(« moving ‘#{filename}’ to ‘#{new_path}’ ») File. Cch To Rule Trong Outlook For Mac Tolerance Data Keygen 2009 Nissan shift# default source dir is current dirif (source_dir == nil) source_dir = » « end #destination is second argument, otherwise same as sourcedest_dir = ARGV.. shift# default destination dir = source dirif (dest_dir == nil) dest_dir = source_dirend# begin the flattening process flatten(source_dir, dest_dir).. « Move all the files from the tree starting at source_dir »"into dest_dir out of the tree »# directory listings to skip$excludes = [‘.. dirname(filename) + « / » == dest_dir puts « file #{filename} already in #{dest_dir} » return end # get the straight filename, no path fname = File. 6e4e936fe3 Hp 5940 Windows 7 Driver 6e4e936fe3 Cms Ships New Bounceback Professional For Mac