سؤال

I need to set up a batch file that will copy files from a preset directory, several layers down, organized into a folder in the current directory using batch files.

The file structure looks something like this,

AAA
--0001
----textures
------file1.tga
------file2.tga
------file3.tga
--0002
----materials ...
--0003
----textures ...
--0004
----scripts ... etc
--0005 ...
--0006 ...
BBB
--0001 ... etc
---textures ... etc
CCC ...
DDD ... etc

I want to move each textures, materials, models (etc.) folders into a single folder beneath the parent item (eg. AAA) so that the folder structure then looks like this, with all sub-files in tact,

AAA
--textures
--materials
--models
--scripts

I've been trying to use a code similar to this, with no success as of yet,

for /d %%a in ('dir /b .\AAA*\textures') do copy "%%a" ".\AAA"

Whereas the wildcard would go between 'AAA' and 'textures' folders. The same would apply for every other 2nd-generation sub-folder.

I just tried another version of the command which moved the files, but not the folder. I'm launching the batch file from within the "AAA" folder.

for /d %%a in (0001) do copy "%%a" "."

I think the issue is not knowing how to properly input directory wildcards into the "for" command, which could be a very simple fix.

Any help would be greatly appreciated beyond measure.

هل كانت مفيدة؟

المحلول

Put this code in a .bat file, and run it inside your AAA directory

for /f "tokens=*" %%a in ('dir /b') do robocopy %%a . /s /move
  • for /f "tokens=*" means that all the returned values by 'dir /b' will be processed
  • dir \b will list the directory in bare format
  • robocopy is the main command, that will do the copy job.
  • source %%a is the variable containing the iterated subfolder name {0001\textures, 0002\materials, ...}
  • destination . means copy to the working directory, which is AAA in our case
  • option /s to search subdirectories
  • option /move to move instead of copy
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top