Automatically move all subfolders in a folder...

R

Rich

I need a batch file or a program that will search all subfolders in a
specific directory for a specific file. When it finds a subfolder with that
file in it I need
it to move that entire subfolder to another folder at another location such
as the desktop.

I'm no programmer and have no clue how to go about doing this. Does anyone
have any suggestions?

TIA, Rich
 
D

David Candy

for /r %A in (.) do @If exist "%A\02a.jpg" echo %A

This will find a file called 02a.jpg and display the folder.
 
R

Rich

I run a game server and I need to be able to scan all folders in the client
directory for a file called 'autoban' and a file called comments.txt. Any
folder that contains either or both of these files needs to be moved to a
different location.

We're talking over 300+ folders. I'd like it to be automated but have no
idea how to program a batch file to do so. I think I need more than what you
gave me.

I do appreciate the response. Is there anything else you can give me?
"David Candy" <.> wrote in message
for /r %A in (.) do @If exist "%A\02a.jpg" echo %A

This will find a file called 02a.jpg and display the folder.
 
D

David Candy

I done all that is possible with the incomplete program specifications you have provided. The hard part I've shown you how to do.


@Echo off
set cFlag=
for /r %%A in (.) do (
If exist "%%A\autoban" set cFlag=1
If exist "%%A\comments.txt" set cFlag=1
If defined cFlag Echo %%A
set cFlag=
 
3

3c273

If you have Python installed (www.python.org), the following script should
do what you want. All you have to do is insert the correct paths. This is
guaranteed to screw your system up royally, so make a backup and test it on
a non-production system ;-).
Louis
Disclaimer: I am not a programmer but this worked on my machine.

-----begin script-----
import os

srcpath = r'path\to\search\directory' ##Insert path between quotes
dstpath = r'path\to\destination\directory' ##Insert path between quotes
srcfile1 = 'autoban' ##This is case sensitive
srcfile2 = 'comments.txt' ##This is case sensitive

for paths in os.walk(srcpath):
for files in paths:
if srcfile1 in files or srcfile2 in files:
mycommand = 'move ' + paths[0] + ' ' + dstpath
os.popen(mycommand)
-----end script-----
 
R

Rich

Ok, let me try to be more specific:

The folder to be searched is the My Documents\My
Games\Freelancer\Accounts\Multiplayer folder.

Within that folder are over 1000 subfolders. Each of these folders contains
the individual player files for each player who plays on our server. Some of
those players were very naughty and did dastardly things such as cheating or
violating server rules. Those folders contain a file named autoban and/or
comments.txt. It is these folders that need to be moved to the folder My
Documents\My Games\Freelancer\Accounts\Multiplayer\Banned

If there's anything else I need to give you, please let me know.

Thank you very much for your assistance.

Rich
"David Candy" <.> wrote in message
I done all that is possible with the incomplete program specifications you
have provided. The hard part I've shown you how to do.


@Echo off
set cFlag=
for /r %%A in (.) do (
If exist "%%A\autoban" set cFlag=1
If exist "%%A\comments.txt" set cFlag=1
If defined cFlag Echo %%A
set cFlag=
 
R

Rich

<quote>This is guaranteed to screw your system up royally, so make a backup
and test it on a non-production system ;-).</quote>

This part makes me very nervous.....


3c273 said:
If you have Python installed (www.python.org), the following script should
do what you want. All you have to do is insert the correct paths. This is
guaranteed to screw your system up royally, so make a backup and test it
on
a non-production system ;-).
Louis
Disclaimer: I am not a programmer but this worked on my machine.

-----begin script-----
import os

srcpath = r'path\to\search\directory' ##Insert path between quotes
dstpath = r'path\to\destination\directory' ##Insert path between quotes
srcfile1 = 'autoban' ##This is case sensitive
srcfile2 = 'comments.txt' ##This is case sensitive

for paths in os.walk(srcpath):
for files in paths:
if srcfile1 in files or srcfile2 in files:
mycommand = 'move ' + paths[0] + ' ' + dstpath
os.popen(mycommand)
-----end script-----


Rich said:
I run a game server and I need to be able to scan all folders in the client
directory for a file called 'autoban' and a file called comments.txt. Any
folder that contains either or both of these files needs to be moved to a
different location.

We're talking over 300+ folders. I'd like it to be automated but have no
idea how to program a batch file to do so. I think I need more than what you
gave me.

I do appreciate the response. Is there anything else you can give me?
"David Candy" <.> wrote in message
for /r %A in (.) do @If exist "%A\02a.jpg" echo %A

This will find a file called 02a.jpg and display the folder.
--
-------------------------------------------------------------------------- ------------------------
How to lose a war in Iraq
http://webdiary.com.au/cms/?q=node/1335#comment-48641
=================================================
 
D

David Candy

@Echo off
set cFlag=
for /r "%userprofile%\My Documents\My Games\Freelancer\Accounts\Multiplayer" %%A in (.) do (
If exist "%%A\autoban" set cFlag=1
If exist "%%A\comments.txt" set cFlag=1
If defined cFlag Xcopy /i "%%A" "%userprofile%\My Documents\My Games\Freelancer\Accounts\Multiplayer\Banned\%%~nxA"
set cFlag=
)

Of course it will find the files in banned and error trying to copy them over themselves.
 
3

3c273

Any time you use an automated tool to perform tasks on massive amount of
files, you MUST have a backup no matter how good the tool is. It only takes
one little error to make a mess of things. For instance, there is no error
checking in this script so if a file is in use when you try to move its
directory, it will fail and you will end up with files in two different
places. (Probably not the end of the world.) If your power supply dies while
performing this operation with ANY tool, you will likely lose data. (Could
be the end of the world.) Don't do anything automated to your data without a
backup.
All that said, if you have a good backup, the script will do what you need
as long as NONE of the files are locked and nothing else out of the ordinary
happens. When it finds one of the files selected, it just call the "move"
command just as if you had typed it at a command prompt.
No matter what method you end up using, make a backup and good luck!
Louis
 
R

Rich

ermmm,

this will MOVE each subdirectory in the first directory to the Banned
folder? I need the whole folder moved, not just copied.

Again, thanks much for your patience.

Rich


"David Candy" <.> wrote in message
@Echo off
set cFlag=
for /r "%userprofile%\My Documents\My Games\Freelancer\Accounts\Multiplayer"
%%A in (.) do (
If exist "%%A\autoban" set cFlag=1
If exist "%%A\comments.txt" set cFlag=1
If defined cFlag Xcopy /i "%%A" "%userprofile%\My Documents\My
Games\Freelancer\Accounts\Multiplayer\Banned\%%~nxA"
set cFlag=
)

Of course it will find the files in banned and error trying to copy them
over themselves.
 
R

Rich

Well, we're almost there. The script you wrote does almost all I ask. It
finds all the folders that contain the files in question and copies them to
the specified location. The other half of the job is not done yet however.
Once those folders are copied to the "Banned" folder they need to be deleted
from the original folder.

I'm hoping that it's just a single line of code that needs to be added to do
that. I tried changing the xcopy command to the move command but that
accomplished nothing, not even the original copy.
 
R

Rich

haHA, I got it working.

I added the line If defined cFlag rmdir /s /q "%%A" and now it does all that
I need it to do.

Thanks much to both of you for responding and for all your help.

Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top