i want to backup file from C:\ to D:\ but i have some problem about the name of folder .name of folder is "C:\test back" and "D:\new"
this is my code
#echo off
cd\
xcopy C:\test back D:\new
a error is invalid number of parameter.
when i change name of folder test back to test_back it still ok
xcopy C:\test_back D:\new
Can you tell me why and how can i do to batch file xcopy if name of folder have space bar.
Thank you . i'm new to backup file.
This solves the space issue, and should copy the files including folders.
#echo off
cd\
xcopy "C:\test back\*.*" "D:\new" /s/h/e/k/f/c
Related
I have a win-cmd-script "a" saved in folder "f", and want to delete the folder "f" with the script itself. Is that possible, and if yes, how?
I know, that a batch-file can delete itself:
(goto) 2>nul & del "%~f0"
And now I have tried:
set mypath=%~dp0
rmdir %mypath%
But that doesn't work. Any ideas?
You can't remove a folder if any process has the folder as the active folder. If you want to remove it, you need to ensure the cmd process executing the script has moved to a different folder:
#echo off
setlocal
set path_to_del=%~dp0
cd /d %USERPROFILE%
rmdir /s/q "%path_to_del%"
This will remove the folder containing the script, though, it will error out as it attempts to scan the file for the line after the rmdir call. Also, if you have any other tools open in this folder, such as notepad, then the directory will remain.
I am looking for a batch file which enables me to upload selected files(file names have got spaces in between) into the destination folder on SharePoint which is protected by password.
When I run this batch file, file names which I specified need to erase its older versions and move into that place. Also the files which are not matching should exist in the destination folder.
I got below code from :Copy specific files into subfolder in batch
#ECHO OFF
ECHO Start Copy
set "SOURCE_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in"
set "DEST_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in\Files to Import"
set "FILENAMES_TO_COPY=SN_Router_1.ipt SN_Router_2.ipt SN_Router_3.ipt"
pushd "%SOURCE_DIR%"
for %%F IN (%FILENAMES_TO_COPY%) do (
echo file "%%F"
xcopy /Y "%%F" "%DEST_DIR%\"
)
popd
ECHO. done
pause
I need to add username/password somewhere in this code and if possible the code should accept file names with spaces in it.
Thank you
I am trying to copy files from a path which is like as shown below
D:\XXX\XXX\SXX_FX.zip\ADMIN
By using code...
#echo off
Rem This is for copy down all the files in the directory
set origin=D:\NXG\Backup_Prod\SGL_FINANCE\WebFolder\SGL_FINANCE.zip\ADMINAPP
set drive=D:\TEST3
set d1=%date:~4,2%
set d2=%date:~7,2%
set d3=%date:~10,4%
XCOPY "%origin%" "%drive%_%d1%%d2%%d3%.zip*" /s /Y
echo "The program has completed"
But I am getting the error message. File not found - ADMIN.
Is it because I am trying to open the zipped file while copying.
Could you please throw some light on how to unzip that folder on the fly.
Using 7zip
Take a "file.txt" from "Archive.zip" to "Destination\Folder"
"C:\Program Files\7-Zip\7z.exe" e -ir!file.txt "C:\Path\To\Archive.zip" -o"C:\Path\to\Destination\Folder\"
Im trying to create a batch file that will copy a directory to another directory however, the directory I wish to copy too has a portion of the name randomly generated i.e. "jibberish.Directory1".
is there a way to do this ?
I was trying something like:
XCOPY "%~dp0DATA\test" "%APPDATA%\Application1\Directory\*Directory1\" /E /C /R /I /K /Y
but total fail. Any help would be greatly appreciated :) Thanks!
xcopy does not support wildcards in directory names. Therefore a for loop is additionally necessary for this task which is as follows:
In folder C:\Temp there is the batch file DuplicateFolder.bat with the code below.
The folder to duplicate is DATA\test in directory of the batch file.
C:\Temp\DATA\test contains:
SubFolder1
FirstFile.txt
Second File.txt
Sub Folder 2
ListFile.csv
Readme.txt
All these subfolders and files should be copied to each subfolder in %APPDATA%\Application1\Directory ending with a number after a dot.
%APPDATA%\Application1\Directory contains for example:
Folder abc.1
Folder e-g.2
Folder h to k.3
Folder last.4
Folder not changed
The last folder should be ignored as it does not contain a dot and a number at end.
The result should be for example for the first subfolder Folder abc.1:
Folder abc.1
SubFolder1
FirstFile.txt
Second File.txt
Sub Folder 2
ListFile.csv
Readme.txt
Code of DuplicateFolder.bat is:
#echo off
set "SourceFolder=%~dp0DATA\test"
for /D %%F in ("%APPDATA%\Application1\Directory\*") do (
if not "%%~xF" == "" %SystemRoot%\System32\xcopy.exe "%SourceFolder%" "%%~F" /E /C /Q /R /I /K /Y >nul
)
set "SourceFolder="
This batch file just checks if folder name contains a dot without checking if string after dot - the "file extension" referenced with %%~xF - is really a number. This very simple test is very fast.
For details about used command for and an explanation of the parameters and special loop variable references open a command prompt window, execute for /?, and read help output for this command in the console window.
I am trying to copy a folder and paste it in the same directory it was copied from.
For example
C:\Test is the main directory which consists of a folder ACDM, I would like to copy ACDM in the same directory and rename the new folder to ACDM1 which will have all the same files as ACDM has
I would like to do it using command prompt
I tried the following
C:>Xcopy C:\Test C:\Test\ACDM1 /E /U
Cannot perform a cyclic copy
0 File(s) copied
which fails, not sure hoe to add REN command with XCOPY command.
Need help ASAP as i would want to create a batch file which will create a copy of an existing folder and rename it according to a name retrieved from a text file..
xcopy "C:\Test\ACDM\*.*" "C:\Test\ACDM1\" /s/h/e/k/f/c
for /f "delims=" %%a in (yourtextfilename) do xcopy "C:\Test\ACDM" "C:\Test\%%a\" /E
as a .bat file line. Directly from the prompt, change each %% to %
I've assumed (for lack of futher information) that your textfile contains just the one line
ACDM1
neither do you specify the textfilename tou want to use.
xcopy C:\Test\ACDM C:\Test\ACDM1\ /E /Q