my batch script
set "Sourcefolder=D:\PurgeScriptExecute\SourceFile"
set "Destfolder=D:\PurgeScriptExecute\DestFile"
set _NoOfDays=30
robocopy /S /MINAGE:%_NoOfDays% "%Sourcefolder%" "%Destfolder%" /E
echo File copied Successful^>^>%Sourcefolder%>>%Destfolder%
This works perfectly but only for files and not the folders inside the source directory .I don't understand why ??
Note
I don't have to move the files and folders . I need to copy them.
What I want to accomplish can be done with for %%i in (*) do md "%%~ni" however this only works if my batch file is in the same folder as the files I want to process. I want to run a batch file from a another folder.
This is what I have tried so far and it's not working. It is still creating the folders in the same folder I run the batch file.
for %%i in ("D:\test1\*") do md "D:\test2\" "%%~ni"
What am I doing wrong? I have not written a script before.
You need to concatenate the path with the name
like this
for %%i in ("D:\test1\*") do md "D:\test2\%%~ni"
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\"
I am new to batch scripting and trying to write a script which will search the zip files inside a folder and extract if exists using 7-Zip. These two are working fine but i am trying to implement a logic where i need to update the log file which will have the entries which zip file got extracted and which got failed. Can someone help me here as when i tried to append log after extracting its showing all the entries present inside the zip files which i dont want. Below is script.
#ECHO OFF
SET LookForFile="C:\test\Software00*.*"
:CheckForFile
IF EXIST %LookForFile% GOTO RunELK
#ECHO TIMEOUT /T 20 >nul
GOTO CheckForFile
:RunELK
ECHO RunELK for this file : %LookForFile%
"C:\Program Files\7-Zip\7z.exe" e "C:\test\Software00*.*" -oC:\test >> C:\test\LOG1.LOG
I have a batch script as follows.
D:
del "D:\TEST\TEST1\Archive\*.TSV"
del "D:\TEST\TEST1\Archive\*.TXT"
del "D:\TEST\TEST2\Archive\*.TSV"
del "D:\TEST\TEST2\Archive\*.TXT"
del "D:\TEST\TEST 100%\Archive\*.TSV"
del "D:\TEST\TEST 100%\Archive\*.TXT"
The above code deletes all the ".txt" and ".tsv" files from all the folders except from the folder TEST 100%. For deleting the files from TEST 100% i am getting the error as The Path could not be found. I guess the % symbol in the folder name creates the issue.
Can anyone guide me to resolve the issue and to delete the files from the folder TEST 100%?
You need to escape the % with another...
del "D:\TEST\TEST 100%%\Archive*.TXT"
There's multiple ways of doing things in batch, so if escaping with a double percent %% isn't working for you, then you could try something like this:
set olddir=%CD%
cd /d "path of folder"
del "file name/ or *.txt etc..."
cd /d "%olddir%"
How this works:
set olddir=%CD% sets the variable "olddir" or any other variable name you like to the directory
your batch file was launched from.
cd /d "path of folder" changes the current directory the batch will be looking at. keep the
quotations and change path of folder to which ever path you aiming for.
del "file name/ or *.txt etc..." will delete the file in the current directory your batch is looking at, just don't add a directory path before the file name and just have the full file name or, to delete multiple files with the same extension with *.txt or whatever extension you need.
cd /d "%olddir%" takes the variable saved with your old path and goes back to the directory you started the batch with, its not important if you don't want the batch going back to its previous directory path, and like stated before the variable name can be changed to whatever you wish by changing the set olddir=%CD% line.
Lets say you saved your software onto your desktop.
if you want to remove an entire folder like an uninstaller program you could use this.
cd C:\Users\User\Detsktop\
rd /s /q SOFTWARE
this will delete the entire folder called software and all of its files and subfolders
Make Sure You Delete The Correct Folder Cause This Does Not Have A Yes / No Option
Consider that the files you need to delete have an extension txt and is located in the location D:\My Folder, then you could use the below code inside the bat file.
cd "D:\My Folder"
DEL *.txt
in batch code your path should not contain any Space so pls change your folder name from "TEST 100%" to "TEST_100%" and your new code will be
del "D:\TEST\TEST_100%\Archive*.TXT"
hope this will resolve your problem