0
I have a large number of textfiles that are nested in subdirectories like this:
D:\datafiles_01\01_data\data\{bunchoftextfiles}
\...
\42_data\{bunchoftextfiles}
\...
\99_data\data\{bunchoftextfiles}
D:\datafiles_02\...
D:\datafiles_99\...
I want to remove all the unnecessary "data" folders. However, sometimes the folder is already removed (example 42).
I found this example that does what I want, but only if executed in one of the datafiles_* directories:
for /D %i in (.\*) do @move %i\data\* %i\
How can this be adopted to run through all of the directories?
Check the filepath for '\data' substring presence. I.e. divide it by slash as a delimiter (FOR /F) and check pre-last variable if it is
data
. But I'd recommend to use forfiles for this operation. – Akina – 2019-10-07T11:43:09.907Try this:
for /D %J in ("D:\datafiles_*") do for /D %I in ("%~J\*_data") do (for %H in ("%~I\data\*.txt") do move "%~H" "%~I\%~nxH") & rd "%~I\data"
(therd
command removes emptydata
directories); but what should happen in case a file indata
has got the same name as one in the parent directory? – aschipfl – 2019-10-07T14:14:54.340