Copy multiple files to different directorys

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
psyghotic
Posts: 7
Joined: 02 Mar 2009 03:31

Copy multiple files to different directorys

#1 Post by psyghotic » 02 Mar 2009 03:42

Hi,

I have got a directory, where i place users id files.
These id files have to go to the users own folder on server.
the source is c:/id

files that can be in this folder :

joe.id
jane.id
blabla.id

These files need to be copied to

\\server\NotesProfiles\username\

So for joe.id

\\server\NotesProfiles\joe\joe.id

the id file names can change.

Does somebody has a solution to do this using a batchfile, where i just click the file, without any user input from that point.

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 02 Mar 2009 07:23

This should get you going down a path that would help... with some tweaking.

-Rick

Code: Select all

 
 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION

 For /F "Delims=" %%F In ('Dir /B *.id') Do (
     Set "f=%%~nF"

     If NOT Exist \\Server\NotesProfiles\!f! (
        MD \\Server\NotesProfiles\!f!
     )

     Copy /v %%F \\Server\NotesProfiles

)

psyghotic
Posts: 7
Joined: 02 Mar 2009 03:31

#3 Post by psyghotic » 02 Mar 2009 08:09

Hi,

I got it working now.
but still one issue.

If I copy the id files to the folders on the server (these folders allready exist).
If the folders on the server do not exist, the id file can't be copied and I need an overview of the id files that haven't been copied.

Code: Select all

 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION

 For /F "Delims=" %%F In ('Dir /B *.id') Do (
     Set "f=%%~nF"

     If  Exist c:\test\!f! (
        Copy /v %%F c:\test\!f!
     
 If NOT Exist c:\test\!f! (
        echo This name doesn't exist
     ))
)
pause


So as an example

c:\test\test
c:\test\bla

these folders exist, so test.id and bla.id can be copied.
the folder qwerty doesn't exist so qwerty.id can't be copied and it has to say qwerty.id isn't copied.
This is because the folders are created when checking in the users, the id files are created seperatly. when an id file has no corresponding folder, the name of id file is wrong and has to be done again. and no new folder can be created, this because of login issues.

thanks for the heads up on the code.

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#4 Post by RElliott63 » 02 Mar 2009 09:24

Inside your loop, just add a test for the Folder. This assumes you're looking for folder names that match the File Name of the ID files in the "C:\Test" folder.

Code: Select all

 
For /F "Delims=" %%F In ('Dir /B C:\ID\*.id') Do (
     Set "f=%%~nF"

     If Exist c:\test\!f! (
        Copy /v %%F c:\test\!f!
     )  Else (     
        echo The Folder !f! Does not Exist
     )
)

psyghotic
Posts: 7
Joined: 02 Mar 2009 03:31

#5 Post by psyghotic » 02 Mar 2009 10:04

Hi,

Thanks, this works.
But it is not easy to overview this when it is used to copy for example 100 files.

I get the following in my cmd window :

For each id file I see the complete coding.

Set "f=bla"
If Exist c:\test\bla (Copy /v bla.txt c:\test\!f! ) Else (echo The Folder bla
Does not Exist )
)
1 file(s) copied.
Set "f=blaf"
If Exist c:\test\bla (Copy /v bla.txt c:\test\!f! ) Else (echo The Folder bla
Does not Exist )
)
The Folder blaf Does not Exist

and this for every file.
Is there a way I can not see this and only see The folders that do not exist, like the underlined

psyghotic
Posts: 7
Joined: 02 Mar 2009 03:31

#6 Post by psyghotic » 02 Mar 2009 10:43

Hi,

I got it running.
Just copied the information about the not copied file into a logfile.


Thanks for the help !! :wink:

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#7 Post by RElliott63 » 02 Mar 2009 13:27

Put an "@Echo Off" as the first line of the script. That way the only thing you will see is the "Echo" statement as it happens.

-R

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#8 Post by RElliott63 » 02 Mar 2009 13:28

Put an "@Echo Off" as the first line of the script. That way the only thing you will see is the "Echo" statement as it happens.

-R

Post Reply