Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Move files from original folder to existing folders - w batch file?

24 Mar 2015   #1
jordansl

Windows 7 64
 
 
Move files from original folder to existing folders - w batch file?

My files have a format of "ID_date_time.d7d
Ex: 11111-5_2013_10_07_142149.d7d
The ID is 1111-5 and was tested 10/7/2013 at 2:21:49 PM and the file extension is always .d7d

The local files are automatically saved here by the program generating the data:
C:\Local\Data

I want them copied to the following directory:
E:\common\UserGroup\UserLocation\Test Data\(ID)
For the above example, it would be copied to: E:\common\UserGroup\UserLocation\Test Data\11111-5


Then, upon successful completion of copying the file, I want the file moved to:
C:\IDArchive\Data\Old Data

Then the file should be removed from the original Local folder.

I can do most of this with a batch file, up to the point where I match the file in the Local\Data folder to its proper destination using its ID number. I need to pull the ID number out of the file name and use it to identify its destination - all of the destination folders already exist. I can't figure out the correct code in the batch file to find the ID number and then extract and match it to its folder.

Help?


My System SpecsSystem Spec
.
25 Mar 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Hi Jordansl,

Here's a full solution to the task you mention. A double For /F loop is used to extract this ID from each file name.


Preview:
Code:
@echo off

REM For each file in %source_location%, copy it to
REM %copy_to%\*ItsID*, then move the file to %move_to%.

set from_source="C:\Local\Data"
set copy_to="C:\common\UserGroup\UserLocation\Test Data"
set move_to="C:\IDArchive\Data\Old Data"

pushd "%from_source:"=%"
for /f "delims=" %%A in (' dir /a:-d /b %from_source:"=% ') do (
	for /f "tokens=1 delims=_" %%B in ( "%%~nxA" ) do (
		for %%C in (%COPY_TO%) do (
			if exist "%%~fC\%%~B"\* (
				copy "%%~fA" "%%~fC\%%~B"
			) else (
				echo.& echo A destination directory for the file '%%~fA' does not exist.
				echo Would you like one to be created for it with the file '%%~nxA' copied to it?
				echo If N, the file will not be copied or moved.
				choice & if not errorlevel 2 md "%%~fC\%%~B" && copy "%%~fA" "%%~fC\%%~B"
			)
		)
	)
	if not errorlevel 2 move "%%~fA" "%MOVE_TO:"=%" || echo.
)
popd


Attached Files
File Type: bat th-365156.bat (889 Bytes, 2 views)
My System SpecsSystem Spec
Reply

 Move files from original folder to existing folders - w batch file?




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Batch File to Move a list of files.
Hey All, I just joined this forum to find some help on a specific topic that I've been researching for like two hours now on google. I have a list of 1300 files that I need to move from one location to another (move not copy). I've found this batch file created by Neutron16 which performs a Move...
General Discussion
Batch file to Sort and Move specific files by identifying word inside
Hi All... I will explain what I need in as much detail as possible. I need a batch file to move specific files into a separate folder,possibly by opening my hex editor,searching for the word "body" ( without the quotes ) and if found ,close hex editor,move file to a folder called "moved" ,then go...
General Discussion
[Help] Batch File move every 15.000 files to another folders
Hi guys I'm new here, please help I have about 2 million email files that i want to convert into mbox files. but the tool i used only can convert every 15.000 files. so i need a batch file that can move this 2 million files into another folder (15.000 files each folder) and the folder name...
General Discussion
Batch code to read, then move files from one folder to another
I'm new to batch coding, so I was hoping someone could help me out. I need to read several .txt files and search them for a specific string, lets say "key1" and "key2." If the file has key1, then it needs to be moved into directory1. If the file has key2, then it needs to be moved to directory2....
General Discussion
Batch file to move (many) duplicted folder contents - Help!!
Hope I can explain my difficulty. I have duplicated folders album name for all my music files. As there is quite a considerable number I wondered if it was possible to batch file (automate) the process. I can not delete "d" as this would delete all the tracks. What I need to do is move the...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 03:24.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App