Hi R user, I was wondering how we can rearrange the folders in R. for example original data has been put with the following arrangement: foldA\subFoldB\subFoldC\subFoldD\subFoldE\ SubFoldE contains several dataset I want to rearrange the subFoldE into following sequence: foldA\subFoldB\subFoldD\subFoldC\subFoldE\ Any suggestions? Thanks [[alternative HTML version deleted]]
Hi Kristi, I assume that B, C and D are not empty, otherwise the answer is trivial. create a directory under B named D move the contents of the old D to the new D delete the directory E beneath the new D create a new directory C under the new D move the contents of the old C to the new C recursively delete D under the new C move the old E under the new C recursively delete the old C Jim On Sat, Oct 1, 2016 at 9:29 PM, Kristi Glover <kristi.glover at hotmail.com> wrote:> Hi R user, > > I was wondering how we can rearrange the folders in R. for example > > original data has been put with the following arrangement: > > foldA\subFoldB\subFoldC\subFoldD\subFoldE\ > > > SubFoldE contains several dataset > > > I want to rearrange the subFoldE into following sequence: > > > foldA\subFoldB\subFoldD\subFoldC\subFoldE\ > > > Any suggestions? > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Thanks Jim for the suggestions. I used following but it seems not working dir.create(foldA\subFoldB\subFoldD\subFoldC\subFoldE) I got a trouble in moving contents of one folder to another. ________________________________ From: Jim Lemon <drjimlemon at gmail.com> Sent: October 1, 2016 6:07 AM To: Kristi Glover Cc: r-help at r-project.org Subject: Re: [R] Rearranging sub-folders, how? Hi Kristi, I assume that B, C and D are not empty, otherwise the answer is trivial. create a directory under B named D move the contents of the old D to the new D delete the directory E beneath the new D create a new directory C under the new D move the contents of the old C to the new C recursively delete D under the new C move the old E under the new C recursively delete the old C Jim On Sat, Oct 1, 2016 at 9:29 PM, Kristi Glover <kristi.glover at hotmail.com> wrote:> Hi R user, > > I was wondering how we can rearrange the folders in R. for example > > original data has been put with the following arrangement: > > foldA\subFoldB\subFoldC\subFoldD\subFoldE\ > > > SubFoldE contains several dataset > > > I want to rearrange the subFoldE into following sequence: > > > foldA\subFoldB\subFoldD\subFoldC\subFoldE\ > > > Any suggestions? > > Thanks > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
If this is a one-time change, it will be simpler to use the Windows File explorer (I assume Windows since you are using backslashes). If it needs to be done using R functions, this seems to work:> dir.create("A/B/C/D/E", recursive=TRUE) > list.dirs("A")[1] "A" "A/B" "A/B/C" "A/B/C/D" "A/B/C/D/E"> file.rename("A/B/C/D", "A/B/D")[1] TRUE> list.dirs("A")[1] "A" "A/B" "A/B/C" "A/B/D" "A/B/D/E"> file.rename("A/B/C", "A/B/D/C")[1] TRUE> list.dirs("A")[1] "A" "A/B" "A/B/D" "A/B/D/C" "A/B/D/E"> file.rename("A/B/D/E", "A/B/D/C/E")[1] TRUE> list.dirs("A")[1] "A" "A/B" "A/B/D" "A/B/D/C" "A/B/D/C/E" ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Kristi Glover Sent: Saturday, October 1, 2016 6:29 AM To: r-help at r-project.org Subject: [R] Rearranging sub-folders, how? Hi R user, I was wondering how we can rearrange the folders in R. for example original data has been put with the following arrangement: foldA\subFoldB\subFoldC\subFoldD\subFoldE\ SubFoldE contains several dataset I want to rearrange the subFoldE into following sequence: foldA\subFoldB\subFoldD\subFoldC\subFoldE\ Any suggestions? Thanks [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.