Don't move a file until a folder doesn't exist

Get help with using AutoHotkey and its commands and hotkeys
eekhelpspike
Posts: 16
Joined: 05 Jul 2015, 17:51

Don't move a file until a folder doesn't exist

27 Jul 2017, 19:20

Hey All,

I'm currently using a simple ahk to move scanned files into a different folder for processing.

Code: Select all

FolderSource = \\SVR1\SCAN\*.*
FolderTarget = \\SVR2\InProcess\*.*
Loop
{
	FileMove, %FolderSource%, %FolderTarget%
	sleep, 500
}
For some reason, the program that is processing the scans is choking. I believe it is because I am throwing too many large files at it, and it is trying to process them all at once. So until I find a better solution, I'd like to dole them out throughout the day so that I can continue to work in my program without interruption, but not have to scan documents every 5 minutes.

I'm working on splitting them into smaller 10 page PDFs, and then I'd like to move each of the files to a processing folder, one by one, after each one is processed.

When I say "processed", I mean the program I'm using moves that file to another folder with and gives it a random name with a .queued extension. The program then creates a folder with the same name as the random file, then deletes that .queued file. After that folder is processed, it gets shipped off to somewhere I'm not privy to, but at that point I'd like to start on the next file.

So, say I scan a 55 page document, then a 20 page document. I'll end up with 2 PDF files with YYYYMMDDHH24MISSMSS.pdf names. I'm going to split them using A-PDF, so i'll end up with something like
20170727180840313.0001.pdf through 20170727180840313.0006.pdf and
20170727180803373.0001.pdf through 20170727180803373.0002.pdf.

e.g. \\SVR1\SCAN\SPLIT\20170727180840313.0001.pdf gets created, then it needs to move to another folder (say \\SVR2\InProcess\) where it will get named 1.b47e3e3d-fd1d-445d-98bf-901abbba5ecc.scan.inbound.queued and soon after a folder will be created in that same directory with the same name as the file minus the 1. and .queued (b47e3e3d-fd1d-445d-98bf-901abbba5ecc). Soon after that, the .queued file gets deleted, and the b47e3e3d-fd1d-445d-98bf-901abbba5ecc folder stays around for a minute or so and gets processed. Then the b47e3e3d-fd1d-445d-98bf-901abbba5ecc folder disappears. At that point, I'd like \\SVR1\SCAN\SPLIT\20170727180840313.0002.pdf to move to \\SVR2\InProcess\

I guess to simplify things, I just want to copy the PDFs over when there doesn't exist FOLDERNAME, where FOLDERNAME is derived from 1.FOLDERNAME.scan.queued. There is other action in this folder, though-- similarly named folders are getting created from similarly named files, but those files are not .queued files, so at least I have that to go on.
Last edited by eekhelpspike on 28 Jul 2017, 11:08, edited 1 time in total.
User avatar
Delta Pythagorean
Posts: 492
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Don't move a file until a folder doesn't exist

27 Jul 2017, 20:36

This would be your best bet, it keeps searching the folder you want to specify to see if it exists, if it does, it waits repeatedly, if it doesn't exist, then it moves on and executes the rest of the code.

Code: Select all

While (FileExist(FolderToSearchFor)) {
	Sleep 10
}
FileMove, % File, % NewLocation
Hope this helps somewhat.
eekhelpspike
Posts: 16
Joined: 05 Jul 2015, 17:51

Re: Don't move a file until a folder doesn't exist

28 Jul 2017, 11:10

Delta Pythagorean wrote:This would be your best bet, it keeps searching the folder you want to specify to see if it exists, if it does, it waits repeatedly, if it doesn't exist, then it moves on and executes the rest of the code.
Thanks for the response. Yes, that is helpful. My problem that I'm running into is that I don't know what that folder will be called. It is named after the file that is created, but I don't know what that filename will be either.
So it goes \\SVR1\SCAN\YYMMDDHHMMSS.0001.pdf > \\SVR2\InProcess\1.RANDOMNAME.scan.inbound.queued > \\SVR2\InProcess\SameRANDOMNAME\
\\SVR2\InProcess\ at any given time can have multiple different RANDOMNAME folders that are created from other source files, but those source files don't have .fax. in them.

e.g. at any given time, the folder I need to watch for can be in a parent folder that contains something like:

file 100.40b64847-4e11-47e0-a1b6-7eddf86192b3.fax.inbound.queued
folder 40b64847-4e11-47e0-a1b6-7eddf86192b3
file 100.17706e27-1241-46fc-9a9b-a565ac3dcc13.fax.inbound.queued
folder 17706e27-1241-46fc-9a9b-a565ac3dcc13
file 1.25d691ea-cb0f-4d92-b963-d3611caed322.scan.inbound.queued
folder 25d691ea-cb0f-4d92-b963-d3611caed322
file 1.94aaaff1-91a9-416a-983e-60ecbb21f93b.scan.inbound.queued
folder 94aaaff1-91a9-416a-983e-60ecbb21f93b

File shows up first, then the folder, and as they get processed, they go away. I think I need to monitor for the creation of the files containing .scan., extract the name (or names) from that file to get the folder name(s), then wait for said folder or folder(s) to get created, then wait for them to go away, then move the next pdf.

I was off on the filenames a little, so I edited the OP.
Vh_
Posts: 201
Joined: 17 Mar 2017, 22:06

Re: Don't move a file until a folder doesn't exist

28 Jul 2017, 19:17

Are there any logfiles associated with the process? I had something similar, finding a randomly generated path folder name. I resulted to reading a log file to obtain the name.

Wildcards can be helpful as well.

Best of luck!

Return to “Ask For Help”

Who is online

Users browsing this forum: A-W-D-space, BushMange, Frosti, Oblituarius and 213 guests