Auto save file from one local disk to another - windows

I have two local drives and one .xlsx file that dropped every day on local drive1.
Is that possible to auto save that file on local drive2 after it appeared on the first?

Create a text file with following content and save it as Batch File(e.g.: copier.bat):
xcopy "e:\source_folder\source.xls" "f:\destination_folder" /e /i /h
Here,
xcopy is a basic copy command
So, when you double click copier.bat your excel file will be copied.
It can be used to copy multiple Files and Folders as well.

Related

Copying 1 file into multiple subfolders

I am a novice. I am trying to copy 1 file into multiple subfolders within windows file explorer. I have successfully copied 1 file into multiple folders within a specified drive using the template below using the CMD prompt.
for /D %a in ("path-to-folder*.*") do xcopy /y /d "Path-to-file\file.FileExt" "%a"
This successfully copies one file to all folders within a specified folder.
Unfortunately I need to copy 1 file into multiple subfolders within a file. I will try to explain as best I can below:
I need an Excel file to copy to all Facility Subfolders within a Facility Folder under Folder1.
File.xls --> Folder 1 --> Facility Folder --> Facility Subfolder
Does that make sense? I need to do this frequently and copy and pasting the excel file to all facility subfolders is time consuming.
Thank you for any assistance!
D

Batch: Copy File from different Subfolders with certain file name to other destination

I am total beginner and need help with copying of files in windows. I have xlsx files in in different subfolders. The name of the files that I want to copy contain (but are not limited) to "Reporting Assessment Tool". I would like to copy all files containing that name and bring them to flat source destination (don't need the folder structure).
source: c:\users\name\desktop\upload
destination: c:\users\source\desktop\tool
So far I have tried the following
cd /D "c:\users\jubalkheimer\desktop\upload" #for /r %%a in ("*Reporting Assessment Tool.xlsx") do (
copy "%%a" "c:\users\jubalkheimer\desktop\tool\"%%~a")
I am not receiving a error message, but files don't get copied....
Can you help?
Many thanks
The batch file code for this task could be:
#echo off
for /R "%USERPROFILE%\desktop\upload" %%I in ("*Reporting Assessment Tool.xlsx") do (
copy /-Y "%%I" "%USERPROFILE%\desktop\tool\%%~nxI"
)
This could be done also with a single command line in batch file:
#for /R "%USERPROFILE%\desktop\upload" %%I in ("*Reporting Assessment Tool.xlsx") do #copy /-Y "%%I" "%USERPROFILE%\desktop\tool\%%~nxI"
The case-sensitive loop variable I holds on each loop run the name of a file with full path without surrounding double quotes found in the specified directory or any subdirectory of that directory matching the file name pattern *Reporting Assessment Tool.xlsx.
For copying the found file with prompting the user of the batch file for overwriting an already existing file with same name in target directory it is necessary to specify as first parameter the string assigned to the loop variable and as second parameter the target path and just file name and file extension of the found file without path. This explains the usage of "%%I" (file name with extension and full path enclosed in double quotes) and "Target Path\%%~nxI" (just file name and file extension with fixed destination path enclosed in double quotes) on COPY command line.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
copy /?
echo /?
for /?
%USERPROFILE% references the predefined environment variable USERPROFILE which holds the path to profile directory of the current user account.
It would be very easily possible to do this task also without the usage of a batch file using Windows Explorer.
Navigate to folder %USERPROFILE%\desktop\upload
Run in that folder a search for *Reporting Assessment Tool.xlsx
Windows Explorer automatically searches recursive in that folder and all subfolders for files matching this file name pattern.
Select all found files with Ctrl+A (select All).
Prepare for copying all selected files with Ctrl+C (Copy).
Navigate to folder %USERPROFILE%\desktop\tool
Paste the files prepared for copying with Ctrl+V (Paste) which results in copying the files now.

How to use a batch file to delete a line of text in a bunch of text files?

I have a bunch of txt files in my D drive which are placed randomly in different locations. Some files also contain symbols. I want a batch file so that I can delete their specific lines completely at the same time without doing it one by one for each file and please refer to a code which does not create a new text file at some other location with the changes being incorporated i.e. I do not want the input.txt and output.txt thing. I just need the original files to be replaced with the changes as soon as I click the batch file.
e.g
D:\abc\1.txt
D:\xyz\2.txt etc
I want both of their 3rd lines erased completely with a single click and the new file must be saved with the same name in the same location i.e. the new changed text files must replace the old text files with their respective lines removed. Maybe some sort of *.txt thing i.e i should be able to change all the files with the .txt extensions in a drive via a single batch file perhaps in another drive,not placing my batch file into each and every folder separately and then running them. Alternatively a vbs file is also welcomed.
This uses a helper batch file called findrepl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697
Place findrepl.bat in the same folder as the batch file below.
It will search for every *.txt file on drive d: and remove line 3.
#echo off
for /r "d:\" %%a in (*.txt) do (
echo processing "%%a"
type "%%a"|findrepl /v /o:3:3 >"%%a.tmp"
move "%%a.tmp" "%%a" >nul
)
pause

Find The Real Location Of Rar File After launching a Batch file

Think I have a compressed file named "Target.rar" and its location is Desktop, inside it I have put a batch script. When I open the rar file (without extracting it) I can see the files inside. If I double click my batch script, winRAR first extract all files into temp folder and will run my batch script from there, so the root directory will be Temp folder, But I need to do something on .rar file location (which is desktop here).
How to get real location of Rar File?
You can search for the rar file if you are confident that you know there won't be any other files with the same name.
dir /b /s C:\Target.rar
Obviously if you know how deep you have to look you can narrow down the search path, and save some time.
If you know it will at least be under C:\Users\%username% then you can use
dir /b /s C:\Users\%username%\Target.rar

What should I write into the .bat file for it to find all files in folder and replace them with file from another?

What should I write into the .bat file for it to find all files with same names in folder (and it's sub folders) and replace them with file from another file (from another folder)?
Is there any fast way if we have 1 000 000 folders with nearely 10 000 files for replacement?
Try
XCOPY /U
/U will make it only copy files from the source to files in the destination, it won't copy any files that do not already exist (which is what I think you are asking for).
To copy files with the same names from c:\weebles to c:\wobble you would do
XCOPY c:\weebles c:\wobble /U /Y
Specify /U to only copy files that already exist in the destination
Specify /Y to copy without asking your permission to overwrite each file (will get tedious really quick).
For more info, open a command prompt and type
help xcopy
IMPORTANT: Before you try this (or a variant) do either:
A backup of your destination folder
A test on some folders that don't matter
Would be a shame to go all gung ho, start the copy then regret it! :-)

Resources