logo
down
shadow

Open folder or create folder if doesn't exist with different constant parent folder can be on 3 different path


Open folder or create folder if doesn't exist with different constant parent folder can be on 3 different path

By : dawn clark
Date : November 20 2020, 04:01 AM
it helps some times Lots of options:
If you have a file server, move the files there and use \\servername\share
code :
Path = DLookup("fieldUserPath", "tblUsers", "fieldUsername = '" & Environ("USERNAME") & "'")


Share : facebook icon twitter icon
7zip / winrar command to extract a folder with path intact to specific folder but excluding parent source path

7zip / winrar command to extract a folder with path intact to specific folder but excluding parent source path


By : Selina Zhang
Date : March 29 2020, 07:55 AM
I wish this helpful for you example , Finally this gave me the result.
to winrar support.
code :
rar x -ep1 sample.rar rising\dawn\* d:\e\delete\
Create new folder if path doesn't exist (else paste in existing folder)

Create new folder if path doesn't exist (else paste in existing folder)


By : Excel Ogre
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've made an Excel sheet which processes data to a Sheet and Saves it as a new workbook in a certain Folder - Subfolder (named like the first part of the file names). , Here you go :
code :
If Dir(sMainFolder & "\"& sSubFolder & "\", 16) <> vbNullString Then
Else
    MkDir (sMainFolder & "\"& sSubFolder & "\")
End If
Drive Api save to folder, if folder doesnt exist, create than save

Drive Api save to folder, if folder doesnt exist, create than save


By : JugHearts01
Date : March 29 2020, 07:55 AM
this will help Remember, that in the GooDrive universe, the tree structure (folder, subfolder, ...) is a mirage. The Drive is a flat system of objects (files, folders) where one of the metadata fields is a 'set of parent IDs', that actually forms the notion of parentobject - childobject structure. Actually the classic tree (one parent many children) is not even enforced, so a child object can 'appear' in more that one parent.
This fact explains that you CAN NOT create an OS type of path in one shot. The objects (parents) must be created before their IDs can be plugged into child objects' metadata.
code :
    if folder exists
      return it's ID
    else
      return ID of newly created one

   create a child object with parent's ID
   / MYROOT / 2015 / 2015-12
new Thread(new Runnable() {
  @Override
  public void run() {
    DriveId Id = getFolder( getFolder( getFolder(
          Drive.DriveApi.getRootFolder(mGAC).getDriveId(), "MYROOT"),
        "2015",
      "2015-12"
    );
  }
}).start();

GoogleApiClient mGAC;

DriveId getFolder(DriveId parentId, String titl) {
  DriveId dId = null;
  if (parentId != null && titl != null) try {
    ArrayList<Filter> fltrs = new ArrayList<>();
    fltrs.add(Filters.in(SearchableField.PARENTS, parentId));
    fltrs.add(Filters.eq(SearchableField.TITLE, titl));
    fltrs.add(Filters.eq(SearchableField.MIME_TYPE, "application/vnd.google-apps.folder"));
    Query qry = new Query.Builder().addFilter(Filters.and(fltrs)).build();

    MetadataBuffer mdb = null;
    DriveApi.MetadataBufferResult rslt = Drive.DriveApi.query(mGAC, qry).await();
    if (rslt.getStatus().isSuccess()) try {
      mdb = rslt.getMetadataBuffer();
      if (mdb.getCount() > 0)
        dId = mdb.get(0).getDriveId();
    } catch (Exception ignore) {}
    finally { if (mdb != null) mdb.close(); }

    if (dId == null) {
      MetadataChangeSet meta = new Builder().setTitle(titl).setMimeType(UT.MIME_FLDR).build();
      DriveFolderResult r1 = parentId.asDriveFolder().createFolder(mGAC, meta).await();
      DriveFolder dFld = (r1 != null) && r1.getStatus().isSuccess() ? r1.getDriveFolder() : null;
      if (dFld != null) {
        MetadataResult r2 = dFld.getMetadata(mGAC).await();
        if ((r2 != null) && r2.getStatus().isSuccess()) {
          dId = r2.getMetadata().getDriveId();
        }
      }
    }
  } catch (Exception e) { e.printStackTrace(); }
  return dId;
}
  fromPath(Drive.DriveApi.getRootFolder(mGAC).getDriveId(), "MYROOT/2015/2015-12/file.jpg");
  ....
  void fromPath(final DriveId parentId, final String path) {
    if (parentId != null && path != null) {

      final int idx = path.indexOf('/');
      if (idx < 0) {
        // reached last path item - probably file name
        // CREATE FILE WITH patentID AND QUIT
        return;    //--- DONE -------------------->>>
      }

      final String titl = path.substring(0, idx);

      ArrayList<Filter> fltrs = new ArrayList<>();
      fltrs.add(Filters.in(SearchableField.PARENTS, parentId));
      fltrs.add(Filters.eq(SearchableField.TITLE, titl));
      fltrs.add(Filters.eq(SearchableField.MIME_TYPE, UT.MIME_FLDR));
      Query qry = new Query.Builder().addFilter(Filters.and(fltrs)).build();

      Drive.DriveApi.query(mGAC, qry).setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
        @Override
        public void onResult(DriveApi.MetadataBufferResult rslt) {
          MetadataBuffer mdb = null;
          if (rslt != null && rslt.getStatus().isSuccess()) {
            try {
              mdb = rslt.getMetadataBuffer();
              for (Metadata md : mdb) {
                if (md.isTrashed()) continue;
                fromPath(md.getDriveId(), path.substring(idx + 1));
                return; //+++ first found, NEXT +++++++>>>
              }
            } finally { if (mdb != null) mdb.close(); }
          }

          MetadataChangeSet meta = new Builder().setTitle(titl).setMimeType(UT.MIME_FLDR).build();
          parentId.asDriveFolder().createFolder(mGAC, meta)
          .setResultCallback(new ResultCallback<DriveFolderResult>() {
            @Override
            public void onResult(DriveFolderResult rslt) {
              DriveFolder dFld = rslt != null && rslt.getStatus().isSuccess() ? rslt.getDriveFolder() : null;
              if (dFld != null) {
                dFld.getMetadata(mGAC).setResultCallback(new ResultCallback<MetadataResult>() {
                  @Override
                  public void onResult(MetadataResult rslt) {
                    if (rslt != null && rslt.getStatus().isSuccess()) {
                      fromPath(rslt.getMetadata().getDriveId(), path.substring(idx + 1));
                      return; //+++ created, NEXT +++++++>>>
                    }
                  }
                });
              }
            }
          });
        }
      });
    }
  }
Google drive folder not create inside parent folder (by Folder ID)

Google drive folder not create inside parent folder (by Folder ID)


By : Victor Nord
Date : March 29 2020, 07:55 AM
To fix this issue I upload the files from my site it will upload to google drive inside the child folder via Google Drive API. Everything working fine. But I want to create a folder inside a parent folder. I have parent folder id. But it cannot create inside parent folder. It will create folder outside of parent folder. , This code work for.
code :
        $ParentfolderId="0Bxy_x723UM3tFFFSSSWWW";           

        $DriveFolderName = "foldername1";
        $folder_mime = "application/vnd.google-apps.folder";
        $folder_name = $DriveFolderName;
        $folder = new Google_Service_Drive_DriveFile(array('parents' => array( $ParentfolderId)));
        $folder->setTitle($folder_name);
        $folder->setDescription($GoogleDriveDesc); 
        $folder->setMimeType($folder_mime);     

        $parent = new Google_Service_Drive_ParentReference();
        $parent->setId($ParentfolderId);
        $folder->setParents(array($parent));

        $newFolder = $service->files->insert($folder);
        $folderId  = $newFolder['id'];

        $file = new Google_Service_Drive_DriveFile();

        if ($folderId != null) {
            $parent = new Google_Service_Drive_ParentReference();
            $parent->setId($folderId);          
            $file->setParents(array($parent));
        } 
        try {
            $data = file_get_contents($filepath);           
            $file->title = $filename;       
            $chunkSizeBytes = 1 * 1024 * 1024;

            $client->setDefer(true);
            $request = $service->files->insert($file);

            $media = new Google_Http_MediaFileUpload(
                  $client,
                  $request,
                  '',
                  null,
                  true,
                  $chunkSizeBytes
            );

            $media->setFileSize(filesize($filepath));
            $status = false;
            $handle = fopen($filepath, "rb");
            while (!$status && !feof($handle)) {
                $chunk = fread($handle, $chunkSizeBytes);
                $status = $media->nextChunk($chunk);
            }

            $result = false;
            if ($status != false) {
                $result = $status;
            }
            return $result;

        } catch (Exception $e) {
             print "An error occurred: " . $e->getMessage();
        }
Creating a folder in vbs if the folder doesnt exist

Creating a folder in vbs if the folder doesnt exist


By : Icaro Vinicius
Date : March 29 2020, 07:55 AM
To fix the issue you can do You forgot the & between "_" and iDate, change it to ... "_" & iDate ...
shadow
Privacy Policy - Terms - Contact Us © bighow.org