powershell - how to rename files to sub directories using cmd -


i have several levels of folders , these folders contain *.csv files. need rename these files in next format:

source sub-directories files:

c:\folder1\folder2\filename1.csv c:\folder1\folder2\filename2.csv ... 

output:

c:\folder1\folder2\folder1_folder2_filename1.csv c:\folder1\folder2\folder1_folder2_filename2.csv ... 

could this?

thanks

your questions says "using cmd" you've tagged powershell. think people assume want powershell answer rather script work in old-style nt command prompt...

get-childitem build list of files under folder, maybe folder1 in case. can filter files ending in ".csv" , move recursively through sub-folders using -recurse switch.

$source_files = get-childitem *.csv -file -recurse 

the $source_files variable include list of files. need loop through list (hint: use foreach) , perform following:

  1. get full name of directory file in
  2. split array divided "\" character
  3. join array again using underscore character
  4. rename file folder names @ front

list others have commented, we're not going write script, people happy people new powershell going in right direction. remember research can!


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -