Hi I would like to copy all the files from a folder on my local machine to a network drive.
I tried using CopyFiles "....\Source*." "\abc\Destination" But its not working.....
I also tried File /r "....\Source*." "\abc\Destination".
Please let me know where am i going wrong. Also please let me know how to copy the folder on the ftp site
Copyfiles uses SHFileOperation internally and should work as long as you follow that api's restrictions, especially the part about full paths: "It cannot be overstated that your paths should always be full paths" and "Standard MS-DOS wildcard characters, such as "*", are permitted only in the file-name position. Using a wildcard character elsewhere in the string will lead to unpredictable results"
Related
I'm making a project out of creating a script to use at work to automate one of our processes.
I'd like the script to check an input for username to search the specified user profile path for any files of .doc,.docx,.pdf,.pst ect. and copy them as is to a created folder on a network drive location.
My main question is what is the command or chain of commands to check folders and sub folders starting at the specified userpath, for JUST files with those extensions and I guess copy them but without getting to a situation where it just copies the same file over and over and over again. Sorry if that's confusing.
This answer provides sample code for recursively traversing a folder tree. A list of extensions could be handled by creating a dictionary:
Set extensions = CreateObject("Scripting.Dictionary")
extensions.CompareMode = vbTextCompare 'case-insensitive
extensions.Add "doc", True
extensions.Add "docx", True
extensions.Add "pdf", True
extensions.Add "pst", True
...
and then checking the extension of the processed files like this:
For Each f In fldr.Files
If extensions.Exists(objFso.GetExtensionName(f.Name)) Then
f.Copy targetFolder & "\"
End If
Next
The trailing backslash is required when the destination is a folder, otherwise you'd have to specify the full target path including the target filename.
I think I have understood most of the requirements, and this can be more easily achieved by using a .BAT file approach within windows. This batch (.Bat) file can run commands such as copy / delete etc.
So create a file called test.bat, and inside the file add the below script:
::XCOPY source [destination]
XCOPY "C:\Temp\*.doc" "C:\Temp\another"
What does this do? Well it uses an XCOPY Command to copy any files within the C:\Temp direcory which have a .doc extension. The files will be copied over to a folder called C:\Temp\another.
The XCOPY takes two primary arguments: source and destination. Source is where the file currently lives, and destination is where you want to copy the files to. More info of all of the options available can be found on:
http://support.microsoft.com/kb/240268
In order to run the file, just double click it, or schedule it to run whenever required.
Let me know if this meets your requirement, I didn't fully understand the bit about an input for a username?
I have a remote server I have read permission (in Windows I labeled it as my X: drive)
The correct path to a file I need to access is:
"X://some dir/some file"
The file that holds the Macro that is running exists in the C: drive. The code below checks to see if the path exists
If dir("X://some folder/some file", vbDirectory) = "" Then
Debug.Print "dir does not exist"
End If
Running that above enters the branch telling me the file does not exist. My questions are:
Do I have to put the name of the drive shorcut? (eg X: or can I put //: instead?)
How can I debug in Excel if I'm even allowed to enter the drive?
First, use backslashes for Windows paths. Second, don't use double backslashes when referring to a mapped drive. (Labelling the drive is meaningless to VBA.) eg:
X:\some folder\some file
If you didn't actually create a mapped drive, you will need to use the UNC or IP (and then you do use the double backslash) . EG:
\\remotehost\path\to\somefolder\somefile.txt
or
\\127.0.0.1\path\to\some folder\some file.txt
I think Tim is correct.
How can I debug in Excel if I'm even allowed to enter the drive?
If you RECORD macro opening a file in your X drive. You will see all the code that you need to put your original code working ;) . Every VBA coder do that kind of tricks.
I want to extract a specific directory form a huge zip file (>5GB) that is somewhat corrupted because of an inevitable bad maintained build system that creates the zip.
The tools such as winrar/7Zip GUI apps have no issues extracting the files, but some command line tools such as mks unzip and 7za fails to extract from the corrupted archive.
After a lot of digging around and trying out many such command line utilities I found out that IZARC successfully extracts files from the archive.
I am running the following command:
IZARCe.exe -e -d -o D:\aHugeZipFile.zip -pD:\temp #"source.txt"
The listing file source.txt contains just one entry:
source/lib/*
which is the only directory in the archive, from where the contents are to be extracted.
But, it is resulting in:
IZArc Command Line Extraction Add-On Version 1.1 (Build: 130)
Copyright(c) 2007 Ivan Zahariev, All Rights Reserved.
http://www.izarc.org contact#izarc.org
Archive File: aHugeZipFile.zip
WARNING: Nothing to do!
I have tried specifying:
/source/lib/*
source/lib/*
source/lib/
source/lib
*source/lib/*
in the listing file, all to no avail! :(
Any pointers on where the error is occurring, and how to fix the issue will be of great help. Thank you in advance!
Using relative or absolute paths for listfiles doesn't appear to work with IZArc. Try using wildcards such as ., *.doc, etc instead of paths in the listfile. Be aware that there appears to be a limitation for the folder depth that IZArc will extract to as well as a tendency to generate CRC errors when files with the same name are present in the same archive, even if they are in different directories.
I would suggest using 7-Zip command-line instead. It can recurse deeply through a file structure without error and can use relative directories and wildcards in its listfiles.
The following 7-Zip command was tested and worked perfectly.
7za x somearchive.zip -o"C:\Documents and Settings\me\desktop\temp_folder\test2" -ir#source.txt -aoa -scsWIN
the source.txt file may contain contain a combination of relative paths and/or wildcards on separate lines such as:
Output/, Folder2/, *, or *.doc.
In the command above: x (extract with full paths), -ir (include filenames, recurse subdirectories), -aoa (overide existing files without prompt), -scsWIN (set charset for list files). You may need to adjust these commands for your situation.
I'm making a project out of creating a script to use at work to automate one of our processes.
I'd like the script to check an input for username to search the specified user profile path for any files of .doc,.docx,.pdf,.pst ect. and copy them as is to a created folder on a network drive location.
My main question is what is the command or chain of commands to check folders and sub folders starting at the specified userpath, for JUST files with those extensions and I guess copy them but without getting to a situation where it just copies the same file over and over and over again. Sorry if that's confusing.
This answer provides sample code for recursively traversing a folder tree. A list of extensions could be handled by creating a dictionary:
Set extensions = CreateObject("Scripting.Dictionary")
extensions.CompareMode = vbTextCompare 'case-insensitive
extensions.Add "doc", True
extensions.Add "docx", True
extensions.Add "pdf", True
extensions.Add "pst", True
...
and then checking the extension of the processed files like this:
For Each f In fldr.Files
If extensions.Exists(objFso.GetExtensionName(f.Name)) Then
f.Copy targetFolder & "\"
End If
Next
The trailing backslash is required when the destination is a folder, otherwise you'd have to specify the full target path including the target filename.
I think I have understood most of the requirements, and this can be more easily achieved by using a .BAT file approach within windows. This batch (.Bat) file can run commands such as copy / delete etc.
So create a file called test.bat, and inside the file add the below script:
::XCOPY source [destination]
XCOPY "C:\Temp\*.doc" "C:\Temp\another"
What does this do? Well it uses an XCOPY Command to copy any files within the C:\Temp direcory which have a .doc extension. The files will be copied over to a folder called C:\Temp\another.
The XCOPY takes two primary arguments: source and destination. Source is where the file currently lives, and destination is where you want to copy the files to. More info of all of the options available can be found on:
http://support.microsoft.com/kb/240268
In order to run the file, just double click it, or schedule it to run whenever required.
Let me know if this meets your requirement, I didn't fully understand the bit about an input for a username?
I am dealing with a massive nest of files and need to find a .htaccess file that is redirecting a single page in my website. I know how ridiculous this sounds: why not just check the directories the page is located within? But the problem is slightly more complicated than that. All I need though, is to search for every .htaccess file under the web folder. Trying a normal search doesn't allow me to select that type of file to search for, and searching for hidden files has just been (who knows why) ignoring the .htaccess files anyway. I can't download any new software to do this for me. but - there must be a way! Even if I could somehow list every file within a directory (and its subdirs) and then organize by file type and scroll down?
I could search for any file with the word "RewriteEngine" , but there are so many files, this would take forever.
Any ideas?
Thanks!
=/ notepad++ is not installed, and I don't have auth to install anything
Use the commandline.
findstr /s RewriteEngine .htaccess
Searches the current directory and all sub directories for .htaccess files containing the string RewriteEngine.
Try searching for files of the form: *htaccess
(spelled precisely like that in the search field)
have you tried using Notepad++. It has a 'Find in files...' option that you could specify the page that it's trying to redirect to, and you could have it check only in *.htaccess files.
Just a thought
Search All files and folders, in All or part of the filename: put ".htaccess" including the quotes.
in the command prompt:
for hidden files: dir /s /b /a:sh *.htaccess>C:\results.txt
for non-hidden files: dir /s /b *.htaccess>C:\results.txt
to search for "RewriteEngine" type dir /s /b rewriteengine
both of these will output the search results to a text file called "results"