Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Moving a fix numbers of files to a new folder.


  • Please log in to reply

#16
Ztruker

Ztruker

    Member 5k

  • Technician
  • 7,091 posts
Ax, if you modify this:

for /f "tokens=*" %%a in ('dir /b "%path%"') do call :movefile "%path%\%%a"

to this

for /f "tokens=*" %%a in ('dir /b/s "%path%"') do call :movefile "%path%\%%a"

That would start at the specified directory and traverse all sub-directories.

Edit: Lovely batch file though!

Edited by Ztruker, 08 February 2008 - 08:00 PM.

  • 0

Advertisements


#17
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Thanks Ztruker,

:) I thought there probably was probably an option, I was just too lazy to look when I last posted, haha. I appreciate the compliment as well, but like I said, still a little rough for my liking. :)

MaMister, I'll look into testing something out, probably with Ztruker's suggestion.

Ax
  • 0

#18
tallin

tallin

    Member

  • Member
  • PipPipPip
  • 277 posts
Greetings Ax238,

:) My compliments to you with this thread and all your work done here on the forum..............

kind regards,
  • 0

#19
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Well thank you for the compliment Tallin, I just do what I can where I can and learn along the way. :)

Ztruker, if you know a way to ignore the inevitable blank line at the end of the dir listing, that would be very helpful. It causes some issues that I've had to workaround. I just don't know what the correct if command would be.

Thanks,

Ax
  • 0

#20
Ztruker

Ztruker

    Member 5k

  • Technician
  • 7,091 posts
Ax, post (or send via PM) what you have and let me look at it.
  • 0

#21
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
I haven't yet changed anything from the batch file I originally zipped. You can see goto in there that handles the error currently.
  • 0

#22
Vaillant

Vaillant

    Member

  • Member
  • PipPipPip
  • 495 posts

Thanks it works!!!

Only 2 things:

1. Moved0 goes inside of Move1.
2. It has a error "The process cannot access the file" (maybe thats why Moved2 has only 2999 files?)

The rest of the folders where good!!!!!!!!

Btw, is it possible to make it search for subfolders, calculate total and move all files in to the Moved named folders too?

If not then is ok, you already save my day.... :)


Sounds to me like we'd need to reset the variable values at the beginning, or end, of the script ?
  • 0

#23
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Which part of the issue are you addressing your suggestion to, Vaillant?
  • 0

#24
Vaillant

Vaillant

    Member

  • Member
  • PipPipPip
  • 495 posts
1. Moved0 goes inside of Move1.

im no batch file expert, my class only covered the basics unfortunately, but considering this is a looping batch, maybe the variables need to be reset to avoid these kinds of complications...
  • 0

#25
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
You've got me interested...

In the batch file, I'm not really storing the output folder name (moved0, moved1, etc). What is happening is for every x number of files, a folder value is incremented. This is appended to "moved" to create the new output folder. The folder increment value is set and checked every time it goes through the loop.

I'm not sure I quite understand what you want to reset or how it will resolve the issue. Maybe you can explain your thinking a bit more in the context of the script.

Thanks much.
  • 0

Advertisements


#26
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts

What total are you wanting to calculate? The number of files in a folder?

Hmm, let say I have 5 sub folders with different amount of files, I would like to total them and move all into 3000 per folder? without the tree structure, just files total up and split the folder.

Thanks.

OK, I got around to creating a new and updated batch file. I renamed it splidir.bat. The command is the same as before (splidir.bat "C:\Test" 3000). Following are changes made:
  • movedn folders start at moved1
  • Searches subdirectories
  • Ignores folders
  • Checks for existence of a folder before creating it
  • Checks the existence of a file before moving it
  • Renames file by appending a count number if file already exists in directory
  • Outputs a message displaying the number of files moved and the number of folders utilized, as below:
    Moved 80000 file(s) into 27 folder(s).
If you need to move all the files into one folder, just choose a number that's arbitrarily larger than the number of files.

Regards,

Ax

Attached Files


  • 0

#27
Ztruker

Ztruker

    Member 5k

  • Technician
  • 7,091 posts
Very nice :)

What/how does the goto :eof work as there is no :eof label?

Edited by Ztruker, 13 February 2008 - 08:21 PM.

  • 0

#28
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Thanks Ztruker,

I believe this should answer your question:

GOTO command now accepts a target label of :EOF which transfers control to the end of the current batch script file. This is an easy way to exit a batch script file without defining a label. Type CALL /? for a description of extensions to the CALL command that make this feature useful.


  • 0

#29
Ztruker

Ztruker

    Member 5k

  • Technician
  • 7,091 posts
Thanks Ax. I've written a lot of batch files over the years but never knew about the goto :eof, neat.
  • 0

#30
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
No problem at all, I learned a few new things writing the batch file as well, including the :eof label.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP