Batch for flat move of files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chadam
Posts: 3
Joined: 08 Oct 2014 06:33

Batch for flat move of files

#1 Post by chadam » 08 Oct 2014 06:46

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.

chadam
Posts: 3
Joined: 08 Oct 2014 06:33

Re: Batch for flat move of files

#2 Post by chadam » 08 Oct 2014 07:57

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch for flat move of files

#3 Post by foxidrive » 08 Oct 2014 17:45

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.

chadam
Posts: 3
Joined: 08 Oct 2014 06:33

Re: Batch for flat move of files

#4 Post by chadam » 10 Oct 2014 15:33

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 )

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch for flat move of files

#5 Post by foxidrive » 10 Oct 2014 19:53

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 )
)

Post Reply