Dear all,
I am looking for a batch solution for this: a third party software daily generates files in the following folder structure:
E:\Base\Folder 1\2014_10_06\File1.xml
E:\Base\Folder 1\2014_10_07\File2.xml
E:\Base\Folder 1\2014_10_08\File3.xml
E:\Base\Folder 2\2014_10_06\File4.xml
E:\Base\Folder 2\2014_10_07\File5.xml
E:\Base\Folder 2\2014_10_08\File6.xml
I would like to have a batch doing the following steps:
1. Move the files from all subfolders to a single folder
E:\Data\Collection\File1.xml
E:\Data\Collection\File2.xml
E:\Data\Collection\File3.xml
E:\Data\Collection\File4.xml
E:\Data\Collection\File5.xml
E:\Data\Collection\File6.xml
2. Delete all subfolders of E:\Stamm\Folder 1 and E:\Stamm\Folder 2
The server runs under Windows 2008 R2. It is ensured that all the affected files have unique file names as the third party software automatically numbers the files ascending.
Unfortunately, I'm stuck with my previous approaches.
Batch for flat move of files
Moderator: DosItHelp
Re: Batch for flat move of files
Hello,
thank you for your answer. I already made a test but without success. No files were moved and no folders were deleted.
How can I debug the code?
thank you for your answer. I already made a test but without success. No files were moved and no folders were deleted.
How can I debug the code?
Re: Batch for flat move of files
chadam wrote:Hello,
thank you for your answer. I already made a test but without success. No files were moved and no folders were deleted.
How can I debug the code?
The folders have to exist, or it will not do anything.
If there are any messages on the screen then show them please.
Re: Batch for flat move of files
Here is the final solution for my problem after testing and debugging on the console:
Code: Select all
@echo off
pushd "E:\Data\Collection" && (
for /r "E:\Base" %%a in (*) do ( move "%%a" )
)
FOR /D %%p IN ("E:\Base\Folder 1\*.*") DO ( rmdir "%%p" /s /q )
FOR /D %%p IN ("E:\Base\Folder 2\*.*") DO ( rmdir "%%p" /s /q )
Re: Batch for flat move of files
Change it to this - which prevents a problem if "E:\Data\Collection" doesn't exist for any reason.
Code: Select all
@echo off
pushd "E:\Data\Collection" && (
for /r "E:\Base" %%a in (*) do ( move "%%a" )
FOR /D %%p IN ("E:\Base\Folder 1\*.*") DO ( rmdir "%%p" /s /q )
FOR /D %%p IN ("E:\Base\Folder 2\*.*") DO ( rmdir "%%p" /s /q )
)