Archiving of Files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
payyadi
Posts: 5
Joined: 18 Aug 2013 21:12

Archiving of Files

#1 Post by payyadi » 19 Aug 2013 06:03

Hi Frnds,

I want to archive a list of files whose path+File name are in a text file.

If any one can explain how this can be achieved will be of great help...

Example:
1. Filenames are in a text file like shown below:
Source_filelist.txt
C:/programfiles/abc.txt
D:/source files/src_file.doc
D:/Requirement/xyz.txt

2. Should pick each of these files from there respective paths and Archive it to a different folder.
3. Files should be zipped before keeping in the destination folder.


Please help...

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Archiving of Files

#2 Post by Endoro » 19 Aug 2013 06:39

try this:

Code: Select all

7za a "my archive" "@Source_filelist.txt"

payyadi
Posts: 5
Joined: 18 Aug 2013 21:12

Re: Archiving of Files

#3 Post by payyadi » 19 Aug 2013 23:53

Hi Endoro,
Thanks a lot for your reply,

But I dont want to use 7Zip to make this happen. I'm looking for a solution where we can zip using our Windows .ZIP file extension.

Can you please share an idea on how we can read a line and assign it as path and pick that and archive it as .zip file?

Thanks,
Aditya

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Archiving of Files

#4 Post by Endoro » 20 Aug 2013 00:41

try this:

Code: Select all

for /f "delims=" %%a in (Source_filelist.txt) do "archive program" a "my archive" "%%~a"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Archiving of Files

#5 Post by foxidrive » 20 Aug 2013 00:42

Windows doesn't have a full featured ZIP utility for command line use.

You can use 7-Zip as it creates .ZIP files too. Winzip and Winrar, ZIP/UNZIP are other options.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Archiving of Files

#6 Post by penpen » 20 Aug 2013 13:09

The best you can do with scripts is use VBS in the the way demonstrated here:
http://stackoverflow.com/questions/30211/can-windows-built-in-zip-compression-be-scripted
Although i prefer a hybrid Jscript/batch script, for this you have just to translate the script.

penpen

payyadi
Posts: 5
Joined: 18 Aug 2013 21:12

Re: Archiving of Files

#7 Post by payyadi » 21 Aug 2013 03:07

Hurray Its done :)

@echo on
for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set yyyymmdd=%%k%%i%%j
for /F "tokens=1-2 delims=: " %%l in ('time /t') do set hhmm=%%l%%m
set FileListDir=D:\PS
set FilelistName=PS.txt
set Srcfeed=ABC
set ArchiveFol=D:\ARCHIVE
set TEMPDIR=C:\temp738
rmdir %TEMPDIR%
mkdir %TEMPDIR%
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=" %%g in (%FileListDir%\%FilelistName%) DO (
set "var=%%g"
Copy !var! !TEMPDIR!
)


::VB Script to ZIP the files.
echo Set objArgs = WScript.Arguments > _zipIt.vbs
echo InputFolder = objArgs(0) >> _zipIt.vbs
echo ZipFile = objArgs(1) >> _zipIt.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
echo wScript.Sleep 100 >> _zipIt.vbs

CScript _zipIt.vbs %TEMPDIR% %ArchiveFol%\%Srcfeed%_%yyyymmdd%_%hhmm%.zip

DEL _zipIt.vbs

Post Reply