Move file already open by the script - windows

I will create a python script to download some pdf files from a web site and next save these files in some directories according to data extracted by each pdf. The problem is: I must open a pdf file in my script in ordert to extract data (I use pdfquery) but when I try to move the file to destination directory I get an error: the file is open by another process. I supposse the proces is the script. My qyestion is, it's possible to release the file from the python script and finally move it to the destination without errors?
A solution is copy (instead move) file and delete it manually or create another script which move the files when the "download and extract" script finish is job. But I search a clean approach.

Related

Windows Batch Compressed file is Invalid

I have a batch file that compresses files into a zip folder so I can email the file. The file runs with no issues. However, when I try to open the zip folder, I get the following error:
'Folder is invalid'
and it won't open. Below is the part of the step that compresses the file on Windows Server 2012:
COMPRESS "%DIR_IP_INTERFACES%\SP_Backups\Outbound_GDC_Req.txt" "%DIR_IP_INTERFACES%\SP_Backups\Outbound_GDC_Req_%DATE:/=%_%TIME::=%.zip"
I need it to zip during the batch file, but I will not be the one unzipping. So, I was looking for a standard way to allow anybody to open/unzip the folder when they receive the email (that doesn't require multiple downloads/changes on each computer that might open these files).
Any ideas?

Double click on the zip file has to self-extract the file in the specified path

I have filename.zip file and if double click the file it has to extract the file in the desired location("c:\user\username"). I have tried using the batch file but didnt give me the required result.
#echo on
#set nested=%nested%Z
set _dest=c:\user\username
if NOT EXIST %_dest% md %_dest%
So if i double click on zip file it has to execute batch file to place file in the destination folder path.How can i do that?
If I understand correctly, you simply want to extract a .zip archive to a previously defined directory c:\user\username, when the user clicks that .zip archive.
No, this is not possible.
A .zip file has no default extraction destination. Nor has is a way to execute scripts upon extraction. It is just a container for compressed data. When you click it, your OS runs a program configured to handle .zip files, allowing you to view the contents, extract the contents, etc - but what and how exactly, is up to the user that clicked the file.
What you effectively want to have is an installer. Here are some pointers for options to do that:
Microsoft IExpress
Nullsoft Scriptable Install System (NSIS)
Quasi-installer using 7-zip self-extracting archive

Installer for a .bin file that will run on Ubuntu

I have a .bin file that will comprise of 3 files
1. tar.gz file
2. .zip file
3. install.sh file
For now the install.sh file is empty. I am trying to write a shell script that should be able to extract the .zip file and copy the tar.gz file to a specific location when the *.bin file is executed on an Ubuntu machine. There is a Jenkins job that will pull in these 3 files to create the *.bin file
My Question is how do I access the tar.gz and .zip file from my shell script ?
There are two general tricks that I'm aware of for this sort of thing.
The first is to use a file format that will ignore invalid data and find the correct file contents automatically (I believe zip is one such format/tool).
When this is the case you just run the tool on the packed/concatenated file and let the tool do its job.
For formats and tools where that doesn't work and/or isn't possible the general trick is to embed markers in the concatenated file such that the original script ignores the data but can operate on itself to "extract" the embedded data so the other tool can operate on the extracted contents.

Retrieve zip file from a predefined ftp link using bat or cmd file

I have a pre-defined ftp link with a zip file on the other end that I want to save to a directory on my cloud server (running Windows Server 2008). Once the zip file has been saved to a specified directory, lets say "c:\MyZipFiles\ZipFile-1.zip" for example, I want to unzip the file so that all files contained within the zip file are accessible within the same directory. I'm currently doing this manually and I want to automate this process by creating a .bat or .cmd file that will perform these steps for me.
Once the zip file is unzipped, I have a task in the Task Scheduler of Windows Server Manager ready to use the unzipped files for other things.
The pre-defined link looks something like this:
ftp://idx.realtor.com/idx_download/files.zip
I would greatly appreciate anyone who can help me with this...
Batch file
ftp -s:ftp_cmds.txt host-name-goes-here
unzip local-file.zip
exit
ftp_cmds.txt
username-goes-here
password-goes-here
cd remote-directory-goes-here
get files.zip local-file-name-goes-here.zip
quit
This the batch file uses "unzip" to unzip the archive you can find it here: http://gnuwin32.sourceforge.net/packages/unzip.htm
Either put the binaries in the same directory or put them somewhere else and set your windows PATH
I used my own ftp to test most of this. Your ftp was offline for me, so it might take some tweaking but this should put you in the right direction.

How to find parent ZIP file from arguments when double-clicking in Windows Explorer - .NET 4.0

In Windows Explorer, when you open a ZIP file and double-click a file, say a JPEG file (.jpg), Windows extracts the JPEG file to a temporary folder, and passes the temporary file name to the associated program as the one and only argument, such as "C:\Users\jprice\AppData\Local\Temp\Temp1_<>.zip\<>.jpg"
I noticed that some applications, like the Windows Photo Viewer in Windows 7 know what ZIP file the temporary file came from. You can click next and previous and get the next/previous files from the ZIP file (as you do, they are also extracted to temporary files).
I've googled and prowled through system.io.packaging, but I can't figure out how to get the path of the original ZIP file (the file name is part of the temporary file path).
It's not done with the shell-->open command, Windows Photo Viewer only gets the temporary file name as far as I can tell.
The Photo Viewer command line is
%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1
Which doesn't help. I did use ProcessMon to watch Photo Viewer and saw it read the .zip file (probably using zipfldr.dll) but could not discover how it knew where the original zip file was.
When I try it, I notice that WinZip initializes the spawned process's current working directory to the folder that the .zip resides in. If you can extract the .zip filename from the temp file path (and older OS versions did not do that), then you can reconstruct the original .zip file path.

Resources