Using XCOPY to copy files in a Zipped folder Not Working - batch-file

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\"

Related

Writing batch file to zip a folder using 7zip

In the image above, I have a batch file in script folder that copies all files from shr02 to Tempo using XCOPY
Tempo Folder
I'm trying to run several trial code to list all directories inside Tempo folder Like:
SET tmp="C:\Users\Marc\Desktop\Tempo\."
FOR /d %%D IN (%tmp%) do echo %%~D
However, I am getting confused of getting some folders . and .. and sometimes File Not Found
What I want to accomplish
I want to compress all the contents of Tempo folder using my 7za.exe (which is inside my script folder)
and move it to Final folder. How can I achieve this?
Update
I tried to run this block of code.
SET tmp="C:\Users\Marc\Desktop\Tempo"
SET exe="C:\Users\Marc\Desktop\script\7zip\7za.exe"
SET dst="C:\Users\Marc\Desktop\Final\tmp.7z"
%exe% "a -t7z %dst% %tmp% -r"
Error Message:
Unsupported Command
a -t7z C:\Users\Marc\Desktop\Final\tmp.7z
C:\Users\Marc\Desktop\Tempo* -r

batch file xcopy to a partially unknown directory with a dot ( . ) in

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.

invalid number of parameter Backup file

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

windows batch script to unzip a file

I am trying to create a batch file that gets a zipped folder for that particular date (v_date) from the sftp site and then unzip them. The zip file contains five files that are text documents. I have written batch scripts that successfully get the zip file from the remote site and save a copy of it on the local drive. I need to incorporate the unzip part in to my script.
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
echo option batch continue>FTP_File_Get.txt
echo option confirm off>>FTP_File_Get.txt
echo open Target>>FTP_File_Get.txt
echo lcd "M:\Development\Data History\File" >> FTP_File_Get.txt
echo cd /Export/File >> FTP_File_Get.txt
echo get /Export/File/Filename_%v_date%.zip "M:\Development\DataHistory\Filename_%v_date%.zip">>FTP_File_Get.txt
echo exit>>FTP_File_Get.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\FTP_File_Get.txt"
del FTP_File_Get.txt
This is my code to UNZIP:
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
cd "M:\Development\Data History\"
::SET v_file="M:\Development\Data History\Filename_%v_date%.zip"
::unzip -o %v_file%
"C:\Program Files\7-Zip\7z.exe" e "Filename_%v_date%.zip"
I need to move the extracted files (6 Files) into their respective folders, Any help is greatly appreciated
To unzip the files you can use this command line:
"C:\Program Files\7-Zip\7z.exe" e "filename.zip"
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Use the above code by saving it to .bat file extension
Remember %userprofile% is for the directory, %programfiles% for the program files set as a variable in windows
hope that helps

Copying a Folder and renaming it using command prompt

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

Resources