distributing files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joejames_786
Posts: 17
Joined: 12 Feb 2017 05:11

distributing files

#1 Post by joejames_786 » 06 Apr 2018 07:20

hi

1.SOURCE: I have a folder named (A) which has .data files (1000's) in it (this folder gets updated at regular intervals)


2. DESTINATION: there are 5 folders named (ie 1, 2, 3, 4, 5) which needs to have 3 .data files always (because they get deleted often).

any script to automatically move .data files from folder (A) to each folder (IE 1, 2, 3, 4, 5) and maintain the file count in each folder

:roll:

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: distributing files

#2 Post by penpen » 06 Apr 2018 08:09

How do we decide which files to keep in the "DESTINATION" folders (3 < 1000/5)?

penpen

joejames_786
Posts: 17
Joined: 12 Feb 2017 05:11

Re: distributing files

#3 Post by joejames_786 » 06 Apr 2018 08:17

any file but each folder maintains 3 files

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: distributing files

#4 Post by penpen » 06 Apr 2018 08:48

Maybe i wasn't clear enough.

Assumed the "SOURCE" folder contains the files "000000.dat" ... "012345.dat",
and the "DESTINATION" folder is empty except the empty subfolders "1" ... "5".

Now the script you want to create starts working; possibly doing this:
1. Move files "000000.dat" ... "000002.dat" to "DESTINATION\1"
2. Move files "000003.dat" ... "000005.dat" to "DESTINATION\2"
3. Move files "000006.dat" ... "000008.dat" to "DESTINATION\3"
4. Move files "000009.dat" ... "000011.dat" to "DESTINATION\4"
5. Move files "000012.dat" ... "000014.dat" to "DESTINATION\5"
6. All allowed folders contain the maximum allowed number of files, so what to do next (which files should be deleted)?

penpen

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: distributing files

#5 Post by Aacini » 06 Apr 2018 10:30

Once upon a time, foxidrive wrote a topic that include a series of recommendations useful for beginners in order they wrote questions in the proper way. Although such a topic is a sticky one that appears at the very beginning of this forum, it seems that no one currently read it...

I also collected a series of advices written by foxidrive that comprises a funny and instructive way to indicate beginners why their questions are not clear. I want to remember this one in particular:
on http://www.dostips.com/forum/viewtopic.php?f=3&t=6100&p=38599#p38599 foxidrive wrote: Just commenting here that that is something that wasn't revealed about the task.
I often argue with question-writers about how they should discuss the real task, as it's not our job to drag details of the task out of them.

In this case too, the task is largely unknown - and is like you visiting the dentist to get your tooth fixed, but you won't tell the dentist which tooth hurts.
At least the Dentist can examine your teeth and tell for themselves. :)
(I miss you, foxidrive... :cry: )

Antonio

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: distributing files

#6 Post by Aacini » 06 Apr 2018 11:10

No comments... :cry: :evil:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem "I have a folder named (A)"
cd \A
rem "which has .data files (1000's) in it"
rem *I need to move up to 15 files from it*
set "i=0"
for %%a in (*.data) do (
   set /A i+=1
   set "file[!i!]=%%a"
   if !i! equ 15 goto continue
)
:continue

set "i=0"
rem "there are 5 folders named (ie 1, 2, 3, 4, 5)"
for %%a in (1, 2, 3, 4, 5) do (
   rem which needs to have 3 .data files always"
   pushd %%a
   set "j=3"
   for %%b in (*.data) do set /A j-=1
   for /L %%j in (1,1,!j!) do (
      set /A i+=1
      for %%i in (!i!) do move "\A\!file[%%i]!" .
   )
   popd
)

joejames_786
Posts: 17
Joined: 12 Feb 2017 05:11

Re: distributing files

#7 Post by joejames_786 » 07 Apr 2018 06:37

hi
Antonio that script didn't work


Ill go again


source folder d:\dump

destination folder d:\others\1 ........d:\others\5 (total 5 folders)


the dump folder contains 1000's of .data files (files keep coming in)

the script should check all the five folders in the destination directory for .data files (even 1 is ok but these 5 folders should not be empty) and if found empty should move files from the source folder to the destination folder's)

note : 3 .data files is not mandatory but these 5 folders should not be empty

thanx

joe

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: distributing files

#8 Post by Aacini » 07 Apr 2018 11:17

joejames_786 wrote:
07 Apr 2018 06:37
hi
Antonio that script didn't work

Before my code I posted a reply about how beginners could do better questions. I invite you to read the first topic in this forum, particularly these parts:


By providing poor information about your task the code you are given stands a good chance of failing.


What happens in a thread when incorrect or poor details are supplied: is that the volunteers write a script based upon that information and the next post often comes from the question writer saying "It doesn't work!"

Often a very long series of posts begins where we try to ascertain what the problem is and how the code fails and then what the real details of the task are. The script has to be rewritten, and that just wastes the time of those volunteers who are giving you free code and it is terribly frustrating and unsatisfying for volunteers to have to re-write a script for the same task again.

Don't do this.



In your first request, you said: "SOURCE: I have a folder named (A)", but in your last request it changed to: "source folder d:\dump".

In your first request, you said: "DESTINATION: there are 5 folders named (ie 1, 2, 3, 4, 5)", but in your last request it changed to: "destination folder d:\others\1 ........d:\others\5".

If you consider that my code was wrote using your first specifications, then it should be easy to adjust the code to the new specifications (hint: change "\A" by "d:\dump", etc).

However, in your first request, you said: "DESTINATION folders needs to have 3 .data files always" and in your second post: "each folder maintains 3 files". However, in your last request you said: "even 1 .data file is ok but these 5 folders should not be empty. 3 .data files is not mandatory".

Sorry, I give up... :?

Antonio

PS - I googled "Why doesn't my code work" phrase and found several interesting pages, like these ones:
https://www.quora.com/Why-doesnt-my-code-work-1 wrote: Please be explicit? I think you need to be more explicit when posting programming problems.
- Always mention the results. "Not working" is not a helpful result. What's not working? What are you getting? What's the error?
- Ask better question to get better answer.
https://meta.stackoverflow.com/questions/253787/are-there-legitimate-fix-my-code-questions wrote: Legitimate code troubleshooting questions will contain all of the following:
  • A brief, but specific statement of the problem, telling us precisely what is wrong. "It doesn't work" is not a problem statement.
  • A brief code snippet that reproduces the problem.
  • The exact wording of the error message you are getting, and which line of code is causing it.
  • The desired behavior; what the program is supposed to do.
  • The troubleshooting steps you've attempted so far to isolate the problem.
Questions missing one or more of these things are subject to closure as "insufficient information to diagnose problem."

Questions containing only a code dump with no explanation of the problem, no attempt at troubleshooting yourself, and containing the inscription "How do I fix my code," are specifically off-topic.
https://meta.stackoverflow.com/a/254263/778560 wrote: Why are you telling me all of this?

Because we expect questions asked here to have a certain minimum level of quality.
  • We expect you to describe the problem clearly and accurately, and give us the information we need to answer your question.
  • We expect you to do your own work. We're here to help you, but we're not here to do your work for you, or help you find things on other sites.
  • We expect you to demonstrate that you have some basic skills, so that you will understand the answer we give you. If what you need to do is go read a book, then that's what we're going to tell you to do.

Post Reply