Computing.Net > Forums > Programming > moving files with a .bat

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

moving files with a .bat

Reply to Message Icon

Name: foyaboya
Date: October 13, 2008 at 09:41:04 Pacific
OS: Windows XP
CPU/Ram: pentium 4 & 504 MB
Product: Dell
Comment:

hello, i am moving files with a batch and scheduled tasks. is there a way to select a specific # of files instead of all the say *.html files in a directory? the string i am using is
move /-y *.html (directory)
thanks




Sponsored Link
Ads by Google

Response Number 1
Name: pball
Date: October 13, 2008 at 10:44:50 Pacific
Reply:

If you could explain yourself better I or someone else could help you out. When you say number of files do you mean they are are named by numbers, only move the first 5 in the folder, or something else. Shouldn't be hard to do when you explain some more.


0

Response Number 2
Name: foyaboya
Date: October 13, 2008 at 10:48:10 Pacific
Reply:

sorry, say there 100 .html files, i want to select the first 20 and move them then select the next 20 etc...


0

Response Number 3
Name: pball
Date: October 13, 2008 at 14:36:19 Pacific
Reply:

well this following script will move the entered number html files from the folder the script is in to a folder you choose.
----------------
@echo off

echo enter number of files to move
set /p ep=

set cout=0

setlocal enabledelayedexpansion
for /f "tokens=*" %%x in ('dir /b *.html') do (
move "%%x" (DIRECTORY)
set /a cout=!cout!+1
if !cout!==%ep% goto end
)

:end

pause
----------------

if you wish to move the same number each time replace this

echo enter number of files to move
set /p ep=

with just
set ep=(NUMBER)


There is one oddity to how it moves the files. If you have files with numbers like 001, 002, ..., 099, 100 there will be no issue. If your files are named like 1,2,3,...,98,99,100. This script will move 1,10,11,12,...,19,100 since that is how it "sees" the file listed.

For regular letter names they will be moved in alphabetical order.

Let me know how this works and if there is anything that can be imporved (other than the order thing since that is dos/cmd related, It could be scripted to work but i'm not that good)


0

Response Number 4
Name: Mechanix2Go
Date: October 13, 2008 at 23:33:24 Pacific
Reply:

Depands on how you define 'first 20'.

Anyway, no need to initialize the count.

==================================
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b *.html') do (
set /a N+=1
if !N! geq 20 goto :eof
echo move %%a d:\dest
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: moving files with a .bat

Bat file to move files onto a created subd www.computing.net/answers/programming/bat-file-to-move-files-onto-a-created-subd/19119.html

can I block a port with a Bat file www.computing.net/answers/programming/can-i-block-a-port-with-a-bat-file/15905.html

How do I move files using a .bat? www.computing.net/answers/programming/how-do-i-move-files-using-a-bat/15473.html