Move files folder from one location to one location

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Raghu
Posts: 3
Joined: 04 Sep 2017 19:53

Move files folder from one location to one location

#1 Post by Raghu » 04 Sep 2017 20:23

Hi Everyone,

We are looking to move files and folders from one location to another location is file or folder size is 1MB.

we have created below script and it is not working as expected. Can someone help me

Code: Select all

@ECHO OFF

:: Set following variable for file size in Bytes
SET /A FileSize=1024

:: Set following variable for file extensions to check (*.* = all files)
SET Filter=*.*

:: Set following variable with path to check insided for files
SET Folder=C:\Source

FOR /R "%Folder%" %%F IN (%Filter%) DO MOVE(
IF %%~zF GTR %FileSize% (
ECHO "%%F"
D:\target))
EXIT /B /0
Last edited by dbenham on 05 Sep 2017 02:55, edited 1 time in total.
Reason: Put code in code block

SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Re: Move files folder from one location to one location

#2 Post by SIMMS7400 » 05 Sep 2017 05:19

I"d suggest "echoing" your results prior to moving them in case you see anything awry. If you anticipate a lot of results, consider spooling to a text file to view first.

Code: Select all

@ECHO OFF

FOR /R "%Folder%" %%F IN (%Filter%) DO IF %%~zF GTR %FileSize% ECHO "%%~F"
PAUSE
EXIT /B 0


Once confirmed, please the ECHO portion with the following:

Code: Select all

MOVE /Y "%%~F" "D:\target"


Also, in batch, * = *.*

Let us know how you make out.

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Move files folder from one location to one location

#3 Post by pieh-ejdsch » 05 Sep 2017 06:08

hello Raghu,

if you want to move complete folders and already same folders are present in the hierarchy:move Folders

Phil

Raghu
Posts: 3
Joined: 04 Sep 2017 19:53

Re: Move files folder from one location to one location

#4 Post by Raghu » 05 Sep 2017 10:56

Hi SIMMS74

Thanks for sharing your inputs the script worked for us for copying only files from one location to another.

i have 2 questions:

1. how can i set two folder location as source( my source files will be in 2 locations and target will be one)
SET Folder=C:\Source_1
SET Folder=C:\Source_2

2. How to move entire folder ( Do we need to zip the folder to move to another location?)

:: Set following variable with path to check insided for files

SET Folder=C:\Source

@ECHO OFFFOR /R "%Folder%" %%F IN (%Filter%) DO IF %%~zF GTR %FileSize% MOVE /Y "%%~F" "D:\target"

PAUSEEXIT /B 0


Hi Phil\SIMMS74


can you please help me to move entire folder from one location to another in the above script

SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Re: Move files folder from one location to one location

#5 Post by SIMMS7400 » 06 Sep 2017 01:36

Raghu wrote:Hi SIMMS74

Thanks for sharing your inputs the script worked for us for copying only files from one location to another.

i have 2 questions:

1. how can i set two folder location as source( my source files will be in 2 locations and target will be one)
SET Folder=C:\Source_1
SET Folder=C:\Source_2


Code: Select all

@ECHO OFF

SET Folder1=C:\Source_1
SET Folder2=C:\Source_2

FOR %%A IN ( "%Folder1%" "%Folder2%" )  DO (
   FOR /R "%%~A" %%F IN (%Filter%) DO IF %%~zF GTR %FileSize% MOVE /Y "%%~F" "D:\target"
)
PAUSE
EXIT /B 0


2. How to move entire folder ( Do we need to zip the folder to move to another location?)

:: Set following variable with path to check insided for files

SET Folder=C:\Source

Code: Select all

@ECHO OFF

SET Folder=C:\Source

ROBOCOPY /S /MOVE "%Folder%" "D:\target"


@ECHO OFFFOR /R "%Folder%" %%F IN (%Filter%) DO IF %%~zF GTR %FileSize% MOVE /Y "%%~F" "D:\target"

PAUSEEXIT /B 0


Hi Phil\SIMMS74


can you please help me to move entire folder from one location to another in the above script


The ROBOCOPY solution should be used very carefully. As it's set up, this will copy everything from source to target, and delete everything then from the source.

There are many switches with ROBOCOPY - file size, age etc. Play around with it and let us know if you need any help.

Post Reply