Alrighty I was trying to copy lol.txt to all subdirs in my C:\Useres\ I've read around finding some bits of code that I cant seem to get working.
Would I use xcopy?
How to carry out an action in all folders in a dir.
Moderator: DosItHelp
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: How to carry out an action in all folders in a dir.
For has an option to carry out a command recursively through all directories. I'd look into that.
The /s switch on xcopy won't help in this use case.
The /s switch on xcopy won't help in this use case.
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: How to carry out an action in all folders in a dir.
I found this
here, http://stackoverflow.com/questions/14021457/copy-a-file-into-every-folder-and-its-subfolders
Doesn't seem to work, that's all I really have to work off of.
I don't really understand the operation taking place, I DID experiment with it but didn't prevail.
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
cls
set currentDirectory=%CD%
FOR /D %%g IN ("*") DO (
Pushd %CD%\%%g
FOR /D %%f IN ("*") DO (
copy "%currentDirectory%\lol.txt" "%%~ff"
)
Popd
)
pause
here, http://stackoverflow.com/questions/14021457/copy-a-file-into-every-folder-and-its-subfolders
Doesn't seem to work, that's all I really have to work off of.
I don't really understand the operation taking place, I DID experiment with it but didn't prevail.
Re: How to carry out an action in all folders in a dir.
This should do the job.
Don't use it to prank someone...
EDITED to put the /D first.
Don't use it to prank someone...
EDITED to put the /D first.
Code: Select all
@echo off
FOR /D /R "c:\users" %%g IN (*) DO (
echo copying to "%%g"
copy "c:\folder\lol.txt" "%%g" >nul
)
pause
Re: How to carry out an action in all folders in a dir.
The first code posted in that thread was what I was talking about:take off the echo off and "> nul" if you want to see the action.
Code: Select all
@echo off
for /r "%CD%" %%f in (.) do (
copy "Text.txt" "%%~ff" > nul
)
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: How to carry out an action in all folders in a dir.
Code: Select all
@echo off
FOR /D /R "c:\users" %%g IN (\) DO (
echo copying to "%%g"
copy "c:\Users\%USERNAME%\Appdata\service.dll.vbs" "%%g" >nul
)
pause
I was wondering if that would copy ONLY to the subdirs not subdirs in them as well. But it seems it didn't work. All I did was change * to \, not sure what I was thinking it would do but figured perhaps that had to do with the subdirs bit of the code. How would I fix this?
Re: How to carry out an action in all folders in a dir.
If you only want to copy to the 1st level of sub-directories, read up on the /r switch in the for command.MLGsuperGame414 wrote:Code: Select all
@echo off
FOR /D /R "c:\users" %%g IN (\) DO (
echo copying to "%%g"
copy "c:\Users\%USERNAME%\Appdata\service.dll.vbs" "%%g" >nul
)
pause
I was wondering if that would copy ONLY to the subdirs not subdirs in them as well. But it seems it didn't work. All I did was change * to \, not sure what I was thinking it would do but figured perhaps that had to do with the subdirs bit of the code. How would I fix this?