Rename a dynamic folder in windows using batch script?
2014-04
C:\Users\xxxx\Downloads\CarepointServiceR2_CarepointServiceR2_**109**_artifacts
The Number which is highlighted is dynamically changed each and every day.I have to rename this like CarePointServiceR2.
I Use this:
ren C:\Users\xxxx\Downloads\CarepointServiceR2_CarepointServiceR2_???_artifacts CarePointServicesR2
It was not working. Please help me to get out of this.
The *
is also a wild card
The following should help (assuming that since the name changes each day that it is the only file in the folder - if there are multiple files with different numbers, this won't work).
ren C:\Users\xxxx\Downloads\CarepointServiceR2_CarepointServiceR2_*_artifacts CarePointServicesR2
I want to copy a file (file.txt) inside all folders of a given destination. I want to create a batch file that does the job, but I'm not so skilled in Windows batch syntax.
You can use the advanced version of the for
command available from Windows NT 4 onwards:
You need something like this in a batch file:
for /D %%f in ("%1\*") do copy "%2" "%%f\"
The batch file works as follows:
- The first argument is the destination directory
- The second argument is the file to be copied
The for
command with the /D
switch iterates over all directories in a given path (here: %1
) and invokes a command on each iteration. Said command is the copy operation which copies the file into every directory.
Of course, since the batch file is only a single line you can also execute it directly on the command line. Just note that the variable for for
has only a single %
, then.
You might want to read about Xcopy as well.