I have a simple method to move a folder to a new directory
Dim firstshare As String = "\\myshare\users\" & frmDeparture.txtUsername.Text
Dim destination As String = "\\secondshare\userarchives$\" & frmDeparture.txtUsername.Text
Try
If Directory.Exists(firstshare) Then
Directory.Move(firstshare, destination)
MsgBox("Folder moved from \\firstshare\users")
End If
Catch ex As Exception
MsgBox("Error finding folder")
End Try
This works fine if I set "destination" as a path like "\path\whatever", but if it's a hidden path (with the $) it doesn't work. Is there something special I have to do in order to access a hidden share programatically?
You are most likely trying to move a directory from one volume/partition to another, and you are getting this error :
Source and destination path must have identical roots. Move will not
work across volumes
An explanation of why this is not possible is found Here. The only way you could move directories across different volumes is to create a new directory in the destination volume and copy the files from the source. You could then delete the original files if you wish.
Related
I am looking for suggestions on how to automatically monitor a folder for uploads (pictures only) and move them into another with a specific filename "MyLife" in the prefix and a numbering sequence in the suffix. I store all my pictures in \Documents\Photos\MyLife and they are numbered with digits i.e. MyLife5523.jpg I would like to monitor a folder \Documents\picsupload for images and have a script or program to check \Documents\Photos\MyLife for the last existing file name (number) and rename the image to the next sequential number and move to \Documents\Photos\MyLife
i.e.
\Documents\picsupload has IMG_20170313_123003.jpg, IMG_20170318_123003.jpg, and IMG_20170313_123030.jpg
The program/script checks \Documents\Photos\MyLife and finds the last file is MyLife5523.jpg
IMG_20170313_123003.jpg, IMG_20170318_123003.jpg, and IMG_20170313_123030.jpg are renamed to MyLife5524.jpg, MyLife5525.jpg, and MyLife5526.jpg and moved to \Documents\Photos\MyLife
I currently have AutoHotKey and DropIt installed. However, I'm open to other suggestions.
Respectfully,
JA
Use SetTimer to poll the source directory for files using Loop, FilePattern. When found, use FileMove to move and rename them into your destination folder. Use IniWrite and IniRead to save numeric suffix so you don't have to scan the destination folder every time.
Hello my coding friends.
Sorry to ask this, but I thought it might be quicker to ask if someone has a script like this lying around.
I have about 2000+ files of audio mp3 files logged for a radio station I'm at, and I'd like to put them in to folders according to their recorded log date.
(Yes, I've now fixed the recording to do this correctly from now on, but this is in referent to what I've been doing with it: https://stephenmonro.wordpress.com/2015/05/22/setting-up-an-audio-logger/ )
The files I have are like this: (YYYYMMDD_HH00)
logs\20150424_0300.mp3
logs\20150424_0400.mp3
logs\20150424_0500.mp3
etc.
What I'd like is something like this:
\logs\8 digit date\filename with the same 8 digit date.mp3
Actual
\logs\20150424\20150424_0300.mp3
\logs\20150424\20150424_0400.mp3
\logs\20150424\20150424_0500.mp3
etc.
This is my pseudo code, I've made, but as I'm a little pressed for time and don't have hours to mess around guessing, I just wondered if anyone knew how to do it quickly.
A .VBS file is my prefered language.
Do
Read a filenames first 8 characters {left(8, filename)} (the date)
If not exist, create a folder called that first 8 characters
Move that file into the folder name
Loop (until all files are moved to the right locations)
Your pseudocode looks spot on to me. Assuming every file in your logs folder is consistently named, here's how it could be accomplished using the FileSystemObject library:
Const LOGS_FOLDER = "c:\logs"
Dim objFSO, objFile, strDate, strSub
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(LOGS_FOLDER).Files
strDate = Left(objFile.Name, 8)
strSub = objFSO.BuildPath(LOGS_FOLDER, strDate)
' Create the folder if it doesn't already exist...
If Not objFSO.FolderExists(strSub) Then objFSO.CreateFolder strSub
' Move the file into its proper folder. Use "\" to indicate dest is folder...
objFile.Move strSub & "\"
Next
Actually i have no idea how this kinda disks works. Its the first time i deal with such disk. I putted some pictures in a folder named as oldpics and with a vb code i wanna reach it but some how i just cant find the picture inside it and its imposible cause i know that the picture is in that folder.
'This A_PicRoad is = "\\198.162.1.20\oldpics\" which is exist for sure
If mdiMain.fsoexist.FileExists(mdiMain.A_PicRoad & stock & ".jpg") Then
pic1.Picture = LoadPicture(mdiMain.A_PicRoad & stock & ".jpg")
Set img = New ImageFile
img.LoadFile mdiMain.A_PicRoad & stok & ".jpg"
End If
'But somehow cant find the picture and leaving this if statement without processing anything..
so what could be causing that?
Edit: I just remember that at first i must enter a username and pass while reaching \\198.162.1.20\ after that i can reach \\198.162.1.20\oldpics\..
If it's a normal SMB network share, then you must use a full valued UNC path (Note the preceding \\)
\\198.162.1.20\oldpics\
You can also map a drive and access it via a drive letter.
I am looking for a way to search a specific folder for a subfolder containing a certain string. Below I have listed a function I typed off the top of my head to see if it would work. Well, it does work but when I am talking about searching through 6,000 folders on a network drive it just isn't fast enough.
I'm sure that there is a better way to do it but I can't seem to dig anything up on Google.
Is there an object that allows me to leverage the windows built in file system searching and indexing capabilities?
As an alternative, does someone have a way to optimize my code? The main bottleneck is the usage of instr.
Here is the code:
Function findPath(strId As String) As String
checkObj
Dim strBase As String
strBase = opt.photoBasePath
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim baseFolder As Object
Set baseFolder = fs.getfolder(strBase)
Dim folder As Object
For Each folder In baseFolder.subfolders
If InStr(1, folder.name, strId) > 0 Then
findPath = strBase & "\" & folder.name
Exit Function
End If
Next folder
End Function
P.S. I'm sure someone will suggest modifying my folder structure so that I can programmatically predict the path but for various reason that isn't possible in my case.
You could use the FindFirstFile Win32 API, which allows you to search for files or sudirectories matching a specified name. Additionally, you could also use the FindFirstFileEx function, along with a FINDEX_SEARCH_OPS parameter of FindExSearchLimitToDirectories, which would limit your search to a file that matches a specified name and is also a directory (if the file system supports directory filtering). For more information on using these functions from VB/VBA see the following:
http://www.xtremevbtalk.com/showpost.php?p=1157418&postcount=4
http://support.microsoft.com/kb/185476
http://www.ask-4it.com/how-to-use-findfirstfile-win32-api-from-visual-basic-code-2-ca.html
Consider splitting traversing the folders from finding your key. Instead of the instr test, store the folder names in a table, then use a query on the table to find your target. It might be slower, but searching should be faster.
I would like to modify the filesystem path for tracks on itunes programmatically, so that I can apply a string transformation to some of the tracks locations (which are now stored in a different places on the filesystem).
I've tried using AppleScript to update the location property of the relevant tracks but I get an end-of-file error when calling "set mytrack's location to ..."
I've seen various other hacks online that involve exporting the entire track db, modifying it in XML, and then reimporting it - but that seems to lose too much metadata (such as playlists).
It would really help to see more of your code. Of particular interest is the value you are using and how it is derived. It would also be useful to see the exact error message you get (you should be able to copy the text out of the AppleScript error dialog sheet if you are running the program from Script Editor/AppleScript Editor).
The dictionary entry for the file track class shows its location property being a writable alias value. The problem you are probably running into is that you are not using an alias for the value.
The following code shows how one might change a track's location using an interactive prompt from choose file (which returns an alias):
set m to path to music folder
tell application "iTunes"
set trk to first item of selection
set l to location of trk
if class of l is alias then
set m to l
end if
set {d, a, n} to {database ID, artist, name} of trk
choose file with prompt "Choose the file to use for " & d & ": " & a & "—" & n default location m
set location of trk to result
end tell
The choose file method is not what you want though, since you are doing some kind of automated, string based pathname translation.
When working with pathnames in AppleScript, there are two kinds that you might use: POSIX and HFS. POSIX pathnames have slash delimited components (and allow colons inside any component). HFS pathnames have have colon delimited components (and allow slashes inside any component), and they usually start with a volume name component.
To convert a POSIX pathname stored in a variable str to an AppleScript alias, use the following expression:
POSIX file str as alias
To convert an HFS pathname stored in a variable str to an AppleScript alias, use the following expression:
alias str
For example:
tell application "iTunes"
set trk to first item of selection
set l to location of trk
set newPath to my computeNewPath(POSIX path of l)
set location of trk to POSIX file newPath as alias
end tell
to computeNewPath(pp)
-- presumably something interesting happens here
return pp
end computeNewPath
How to move media files (that are not "organized" by iTunes) to a different location while keeping the iTunes library database (iTunes Library.itl) intact:
Move files to new location (e.g., mv ~/MyMusic /Volumes/Huge/)
Create symlink in old location pointing to new location
(ln -s /Volumes/Huge/MyMusic ~/MyMusic)
Start iTunes (if not already running)
Select all tracks that were moved.
Run this AppleScript:
-- Mark missing tracks (and update database with real path of existing
-- tracks) in iTunes
-- Instructions:
-- * symlink new file location to old location (old location points to
-- new location, file exists)
-- * select tracks to scan/update
-- * run the script
-- * missing tracks are marked with (!) and all other track paths have
-- been updated to the real path (symlinks eliminated) in iTunes
tell application "iTunes"
set fx to fixed indexing
set fixed indexing to true
set Sel to the selection
repeat with i from 1 to number of items in Sel
set trk to item i of Sel
set loc to (get location of trk as text)
end repeat
set fixed indexing to fx
end tell
All tracks should now point to the correct location, and the symlink(s) can be removed. This can be verified by selecting Get Info on a track that was moved and verify that the path points to the new location.
If you didn't get the symlink correct iTunes will display (!) beside each missing track. To fix the issue, simply create a symlink in the old location pointing to the new location and run the script again. Hint: the Get Info dialog can be used to determine the old location of a missing track.
This worked on iTunes 11.0.5
Adding to the previous answer by millerdev I updated the script to work with MacOS Catalina and the new Music app. Just create a $HOME/Library/Music/Scripts directory and place it there.
tell application "Music"
set fx to fixed indexing
set fixed indexing to true
set Sel to the selection
repeat with i from 1 to number of items in Sel
set trk to item i of Sel
set l to location of trk
set location of trk to l
end repeat
set fixed indexing to fx
end tell