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:
- get full name of directory file in
- split array divided "\" character
- join array again using underscore character
- 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
Post a Comment