0

I wish to iterate through a directory containing a dynamic amount of subdirectories (I will be reusing this code for different directories on this machine, one directory has about 160 subdirectories, another has over 1000, etc) and within those subdirectories, there are subdirectories containing folders that contain files. I'd like to move all of the files in the source folder to the destination folder and once all of the files have been moved, I'd like for the source folder to be deleted.

From

 Source
      (dynamic amount of subdirectories)
            Site Visits
                 Field Notes (Destination Folder)
                 Levels (Source folder)

To

 Source
      (dynamic amount of subdirectories)
            Site Visits
                 Field Notes

Here's the code that I have so far:

@ECHO OFF
SETLOCAL EnableExtensions
set "source=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
set "target=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
for /d %%i in ("%source%\*") do (
   pushd "%source%\%%~nxi\site visits\levels prior to WY2016"
   robocopy "%source%\%%~nxi\site visits\levels prior to WY2016" "%target%\%%~nxi\site visits\field notes prior to WY2016" /e /copyall /move
   rd "%source%\%%~nxi\site visits\levels prior to WY2016"
)

I'm new to batch scripting so, I would really appreciate if you can help me in some way. Thanks!

Shadouhan
  • 1
  • 3
  • 1
    What is the problem with the code you have? Does it move the wrong files, or does it through an error? – aschipfl Aug 10 '16 at 18:39
  • The code I have now, for some odd reason doesn't delete the source folder, however it deletes the contents of both folders (source and destination). – Shadouhan Aug 11 '16 at 15:35
  • Perhaps `for /D` does not resolve UNC paths correctly. And you have double-backslashes in the paths as `source` and `target` already contain a trailing backslash. Why do you use `rd` while you already have `robocopy`'s `/MOVE` option? – aschipfl Aug 11 '16 at 16:23
  • I'm using rd to delete the source folder and that could be true that for /D doesn't resolve UNC Paths correctly, I'll check it out but it doesn't seem to be the case – Shadouhan Aug 15 '16 at 17:58

0 Answers0