Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 436 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy a file to all folders batch file?

#1
I need copy `credits.jpg` from `C:\Users\meotimdihia\Desktop\credits.jpg` to `D:\Software\destinationfolder and all subfolders`
I read many and i write

/R "D:\Software\destinationfolder" %%I IN (.) DO COPY "C:\Users\meotimdihia\Desktop\credits.jpg" "%%I\credits.jpg"

then i save file saveall.bat but i run it , it dont work at all.
help me write 1 bat
Reply

#2
Give this a try:

for /r "D:\Software\destinationfolder" %i in (.) do @copy "C:\Users\meotimdihia\Desktop\credits.jpg" "%i"

Of course, if it's to go into a batch file, double the '%'.
Reply

#3
If you can use it: Here is a PowerShell solution (PowerShell is integrated in Windows 7 and available from XP and up):

$file = "C:\...\yourfile.txt"
$dir = "C:\...\YourFolder"

#Store in sub directories
dir $dir -recurse | % {copy $file -destination $_.FullName}
#Store in the directory
copy $file -destination $dir

I'm pretty sure that the last line can be integrated in `dir ...` but I'm not sure how (I do not use PowerShell very often).
Reply

#4
This was the first search I found on google for `batch file copy file to all subfolders`.

Here's a way with [xcopy][1].
There's also [robocopy][2] but that would be too powerful for a simple task like this. (_I've used that for entire drive backups because it can use multi-threading_)

---

But, let us focus on **`xcopy`**.

This example is for saving to a file with the extension `.bat`. Just drop the additional `%` where there is two if running directly on the command line.

```
cd "D:\Software\destinationfolder"
for /r /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K
```

- `cd "D:\Software\destinationfolder"` change directory to the folder you want to copy the file to. Wrap this in quotes if the path has whitespaces.
- the `for` loop - [See help here][3]. Or type `for /?` in a command prompt.
- `/r` - Loop through files (recurse subfolders)
- `/d` - Loop through several folders
- `%%I` - `%%parameter`: A replaceable parameter
- `xcopy` - Type `xcopy /?` in the command line for lots of help. You may need to press <kbd>Enter</kbd> to read the entire help on this.
- `C:\temp\file.ext` - The file you want to copy
- `"%%~fsI"` - Expands `%%I` to a full pathname with short names only
- `/H` - Copies files with hidden and system file attributes. By default, xcopy does not copy hidden or system files
- `/K` - Copies files and retains the read-only attribute on Destination files if present on the Source files. By default, xcopy removes the read-only attribute.

---

The last two parameters are just examples if you're having trouble with any read-only files and will retain the most important file properties.

[Lots more xcopy parameters here][4]

[xcopy examples here][5]

---

Just for completeness. This example below will copy the same file in each folder of the current directory and not any sub-folders. Just the `/r` option is removed for it to behave like this.

```
for /d %%I in (*) do xcopy "C:\temp\file.ext" "%%~fsI" /H /K

```


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through