Move all files to a different direcotry except one file
Moderator: DosItHelp
Move all files to a different direcotry except one file
Hello all,
I need some help to write an bat file that will move all the file to a different directory except for one file with the lastest date stamp? Thanks for your help.
I need some help to write an bat file that will move all the file to a different directory except for one file with the lastest date stamp? Thanks for your help.
-
- Expert
- Posts: 1163
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Move all files to a different direcotry except one file
Try this, changing the source and target directory names for the ones you need. Note that this will also move any folders in the source directory.
Code: Select all
@echo off
cls
set "source_dir=C:\where\the\files\are"
set "target_dir=C:\where\the\files\will\go"
for /f "skip=1 delims=" %%A in ('dir %source_dir% /b /o-d') do (
move "%source_dir%\%%A" %target_dir%
)
Re: Move all files to a different direcotry except one file
It works very well. Thank you so much for your help.
Re: Move all files to a different direcotry except one file
Sorry. It is only working for the folder that has no space in it. What do I need to do with a space in the source and target directory name? Thanks.
C:\Program Files (x86)\Microsoft SQL Server Compact Edition
Thanks.
C:\Program Files (x86)\Microsoft SQL Server Compact Edition
Thanks.
Re: Move all files to a different direcotry except one file
Any folders or file names that have spaces needs to have quotes around the entire path.
As you can see in the MOVE command there is quotes around the Source but not the target.
As you can see in the MOVE command there is quotes around the Source but not the target.
Re: Move all files to a different direcotry except one file
Thanks for the reply. Here is the modified code, but it is still not working.
@echo off
cls
set "source_dir=F:\log 1"
set "target_dir=F:\log 2"
for /f "skip=1 delims=" %%A in ('dir %source_dir% /b /o-d') do (
move "%source_dir%\%%A" "%target_dir%"
)
Thanks.
@echo off
cls
set "source_dir=F:\log 1"
set "target_dir=F:\log 2"
for /f "skip=1 delims=" %%A in ('dir %source_dir% /b /o-d') do (
move "%source_dir%\%%A" "%target_dir%"
)
Thanks.
-
- Expert
- Posts: 1163
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Move all files to a different direcotry except one file
Not enough double quotes.
Code: Select all
@echo off
cls
set "source_dir=F:\log 1"
set "target_dir=F:\log 2"
for /f "skip=1 delims=" %%A in ('dir "%source_dir%" /b /o-d') do (
move "%source_dir%\%%A" "%target_dir%"
)
Re: Move all files to a different direcotry except one file
loc3loan,
It is just good coding practice to always put quotes around all folder and file paths regardless of them having spaces or not. It does not hurt to have them. So when you see your program failing, you should turn ECHO ON and look at the output to see what the error is and what the batch file is executing. Regardless of that the number one rule is to just use "QUOTES" all the time.
It is just good coding practice to always put quotes around all folder and file paths regardless of them having spaces or not. It does not hurt to have them. So when you see your program failing, you should turn ECHO ON and look at the output to see what the error is and what the batch file is executing. Regardless of that the number one rule is to just use "QUOTES" all the time.
Re: Move all files to a different direcotry except one file
Thank you so much for your help. It is working now. Have a good weekend.